Bonjour
Je ssuis nouveau avec RakNet et un peu moins en C++ mais j'ai une erreur C++
J'essaie d'avoir une classe avec une propriété RakServerInterface *.
Mais j'ai une erreur à l'initialisation. La propriété server n'est pas définie.
Je suis parti du Chat example.
Voisi mes fichiers :
MyServer.h#include "PacketEnumerations.h"
#include "RakNetworkFactory.h"
#include "RakServerInterface.h"
#include "NetworkTypes.h"
#include "BitStream.h"
#include <assert.h>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <conio.h>
#include <windows.h> // Sleep
class CMyServer
{
public:
CMyServer(void);
RakServerInterface * server;
public:
virtual ~CMyServer(void);
}
MyServer.cpp#include "MyServer.h"
CMyServer::CMyServer(void)
{
RakServerInterface * server = RakNetworkFactory::GetRakServerInterface(); //::GetRakServerInterface();
server->InitializeSecurity(0,0);
int i = server->GetNumberOfAddresses();
server->SetPassword("Socrate");
// Record the first client that connects to us so we can pass it to the ping function
PlayerID clientID=UNASSIGNED_PLAYER_ID;
// A server
puts("Enter the server port to listen on");
gets(portstring);
if (portstring[0]==0)
strcpy(portstring, "10000");
puts("Enter the server name (up to 40 characters)");
gets(enumerationDataStruct.serverName);
if (enumerationDataStruct.serverName[0]==0)
strcpy(enumerationDataStruct.serverName, "Default server name");
puts("Enter the server message of the day (up to 50 characters)");
gets(enumerationDataStruct.MOTD);
if (enumerationDataStruct.MOTD[0]==0)
strcpy(enumerationDataStruct.MOTD, "Default MOTD");
// Note this passes by value, because otherwise people could get access
// to and damage our internal data
server->SetStaticServerData((char*)&enumerationDataStruct, sizeof(EnumerationDataStruct));
puts("Starting server.");
}
CMyServer::~CMyServer(void)
{
}
And my main file :
main.cpp#include "PacketEnumerations.h"
#include "RakNetworkFactory.h"
#include "RakServerInterface.h"
#include "NetworkTypes.h"
#include "BitStream.h"
#include <assert.h>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <conio.h>
#include <windows.h> // Sleep
#pragma comment(lib, "RakNetDLL.lib")
int main (void) {
CMyServer* aServer = new CMyServer(); // OK but aServer->server not defined
bool b = aServer->server->Start(32, 0, 30, atoi(aServer->portstring));
if (b)
puts("Server started, waiting for connections.");
else
{
puts("Server failed to start. Terminating.");
exit(1);
}
}
L'erreur est à aServer->server->Start où aServer->server n'est pas défini
Pourriez-vous m'aider svp?