Hello, I have a problem already for like a week and I seriously can't get out of it. Take a look at the screen shot.
The server sends a packet to the client to spawn an NPC. If you look to the top commandline-window, the client does recv the packet good and spawns the NPC, at first with the arguments specified. But after that, and I don't know how it comes, the NPC gets a name as PC:100 and the text he says is a "!" if you can see it.
What am I doing wrong?
Here is the code when im parsing the packets.
while(1) {
packet = Client->Recv();
LoadTime = GetTickCount();
command = strtok(packet, ":");
for(int i = 0; i < 10; i++)
args[i] = strtok(NULL, ",");
switch(Commands[command])
{
case c_Disconnected:
MessageBox(MainWnd, "Disconnected from the server!", "Error:", 0);
exit(0);
break;
case c_Join: {
float endtime = (float)(GetTickCount()-LoadTime)/1000;
cout << "Got packet in " << endtime << " seconds\n" << endl;
cout << "Received Join\n";
GUI::AddMessage(FLAG_SYSTEM, "Connection with the server established.");
cout << "Name was \"" << Player1->GetName() << "\" and is now \"" << Player1->SetName(args[0]) << "\".\n";
}
break;
case c_Mofd:
if(!args[0]) {
Client->Send("NotValid:Mofd,No message of the day specified!");
break; // If there are some arguments empty, just exit to prevent crashes.
}
GUI::AddMessage("Message Of The Day", "%s", args[0]);
break;
case c_SpawnNPC:
if(!args[0] || !args[1] || !args[2] || !args[3] || !args[4] || !args[5]) {
Client->Send("NotValid:SpawnNPC,%s!", (args[0] == 0) ? "No name specified" :
(args[1] == 0) ? "No type specified" :
(args[2] == 0) ? "No X position specified" :
(args[3] == 0) ? "No Y position specified" :
(args[4] == 0) ? "No text specified" :
(args[5] == 0) ? "No HP specified" : "Unknown error");
break; // If there are some arguments empty, just exit to prevent crashes.
}
temp = Client->SpawnNPC(DirectX, args[0], (TYPES)atoi(args[1]), atof(args[2]), atof(args[3]), args[4], atoi(args[5]));
Client->Send("Succes:Succesfully spawned NPC %s saying %s", temp->GetName(), temp->GetText());
cout << "SpawnNPC\n{\n";
for(int i = 0; i < 6; i++)
cout << "\t" << args[i] << endl;
cout << "}\n";
break;
default:
cout << command << " is not a valid command.\n";
break;
}
for(int i = 0; i < 10; i++)
args[i] = 0;
}
}
Excuse me for the length.
If you happen to know what i'm doing wrong, please tell me.
Thanks alot!