Commit 9e4a6cdc authored by Stuart John Watson's avatar Stuart John Watson

Fixed getstring function (mostly) and added more parsing for the welcome mesage

parent 7acc0bc1
......@@ -26,8 +26,8 @@ void datahandler(char *data, long datalength, ENetPeer *connpeer){
int prot = getint(data,off);
int sessId = getint(data,off);
bool passworded = getint(data,off)>0;
char* info = getstring(data,off);
char* auth = getstring(data,off);
const char* info = getstring(data,off);
const char* auth = getstring(data,off);
std::cout << "Connected" << std::endl << " clientNumber:" << mycn << " protocol:" << prot << std::endl;
std::cout << " sessionId:" << sessId << " passworded " << passworded << std::endl;
std::cout << " " << info << ". AuthInfo:" << auth << std::endl;
......@@ -52,7 +52,7 @@ void datahandler(char *data, long datalength, ENetPeer *connpeer){
}
case N_MAPCHANGE:{
char* newmap = getstring(data,off);
const char* newmap = getstring(data,off);
int mode = getint(data,off), u2 = getint(data,off);
std::cout << "Map changed to " << newmap << " on mode " << mode << std::endl;
if (!welcomeMessage || getint(data,off) != N_TIMEUP) break;
......@@ -65,13 +65,18 @@ void datahandler(char *data, long datalength, ENetPeer *connpeer){
case N_ITEMLIST:{
if (!welcomeMessage) break;
std::cout << "Itemlist" << std::endl;
while (getint(data,off) != -1){}// Cheat here till I get this one implemented
if (getint(data,off) != N_TEAMINFO) break;
if (getint(data,off) != N_SETTEAM) break;
}
case N_TEAMINFO:{
if (!welcomeMessage) break;
while (getint(data,off) != -1){}// Cheat here till I get this one implemented
case N_SETTEAM:{
int wn;
while (((wn = getint(data,off)) != -1) && off < datalength){
const char* team = getstring(data,off);
if (!welcomeMessage) int reason = getint(data,off);
std::cout << wn << " changed to team " << team << std::endl;
}
if (getint(data,off) != N_SPAWNSTATE) break;
}
case N_SPAWNSTATE:{
......@@ -86,8 +91,8 @@ void datahandler(char *data, long datalength, ENetPeer *connpeer){
getstring(data,off);
getstring(data,off);
getint(data,off);
char* name = getstring(data,off);
char* team = getstring(data,off);
const char* name = getstring(data,off);
const char* team = getstring(data,off);
int model = getint(data,off);
std::cout << name << " joined the game with client number " << cn << " on team " << team << " with model " << model << std::endl;
if (!welcomeMessage) break;
......@@ -165,6 +170,7 @@ int getint(char *data,int& off){
}
}
/*
char* getstring(char *data,int& off){
//int len = strlen(data+off);
int i;
......@@ -176,4 +182,12 @@ char* getstring(char *data,int& off){
out[++i] = '\x00';
off+=i;
return out;
}*/
const char* getstring(char *data,int& off){
std::string out(&data[off]);
off += out.length()+1;
const char* out2 = out.c_str();
return out2;
}
......@@ -4,5 +4,5 @@
void datahandler(char *,long, ENetPeer *);
int getint(char *,int&);
char getbyte(char *,int&);
char* getstring(char *,int&);
const char* getstring(char *,int&);
#endif
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment