I have a client program that accepts 2 inputs from a player, username & password then sends them off to the server using DarkNet, The server recieves the username then strcat's it to another variable then that variable gets ".xml" strcatted (lol catted) onto the end of it and some irrelevant sutuff happens to it....
The issue here is that it seems strcat is sticking random characters into my new string either the first time it fires, last time, or both times. You can see how this would cause problems.
Here are a few different snippets of code showing everything during the process of taking in the variable all the way down to showing it on the 'console screen'
I've also included a picture of the random characters it sticks
**NOTE** this is most likely a server side issue since the random characters are ALWAYS the same ones *unless* I restart my server program, then its a different set of random characters. =[
It also seems as if this happens Most Of The Time, sometimes (hardly any) no random characters get strcatted and all goes well.
Getting text from the user & sending it to the server (class constructor):
void textbox::Do()
{
int mc = dbMouseClick();
int mx = dbMouseX();
int my = dbMouseY();
if (mc == 1)
{
if (mx > XPos+5 && mx < XPos+SpriteX-5 && my > YPos+6 && my < YPos+SpriteY-6)
{
selected = true;
} else {
selected = false;
}
}
if (selected == true)
{
dbText(0,0,dbStr(dbScanCode()));
if (dbKeyState(14) == 1)
{
if (numcount >= 0)
{
if (bkpress == false)
{
numcount--;
curtxt[numcount] = '';
bkpress = true;
}
}
}
if (dbKeyState(14) == 0)
{
bkpress = false;
de = dbGetEntry();
if (de != NULL)
{
if (strcmp(de, blank))
{
strcat ( curtxt, de );
numcount++;
dbText(10, 10, "running");
}
}
dbClearEntryBuffer ( );
}
}
dbPasteSprite ( Sprite, XPos, YPos );
dbText ( XPos+10, YPos+12, curtxt );
dbText ( XPos-100, YPos+12, dbStr(numcount) );
}
Server side to recieve the message *DarkNet* (normal function)
void Net_Check_Tcp ( )
{
for(int nClient = 1; nClient<=MaxClients; nClient++)
{
int TcpPackets;
TcpPackets = mnRecvTCP(0,RecvPacket,nClient);
if(TcpPackets > 0)
{
int Operation = mnGetInt(RecvPacket);
if(Operation == OP_VERIFY_ACCOUNT)
{
const char *iv1 = mnGetStringC(RecvPacket, 0, true);
const char *iv2 = mnGetStringC(RecvPacket, 0, true);
ply[nClient].Login ( nClient, iv1, iv2 );
delete[] iv1;
delete[] iv2;
}
}
}
}
ply.Login(...) (class constructor):
void tclient::Login ( int clientnumber, const char *username, const char *password )
{
char v1[255];
char v2[255];
const char *cc1 = ".xml";
const char *docpass;
bool loadok;
int test1;
strcat ( v1, username );
strcat ( v1, cc1 );
strcat ( v2, password );
TiXmlDocument ( doc );
loadok = doc.LoadFile ( );
if (loadok == true)
{
docpass = doc.FirstChildElement("Account")->FirstChildElement("Login")->Attribute("Password");
test1 = strcmp ( docpass, v2 );
if (test1 == 0)
{
ClientNumber = clientnumber;
Username = username;
Password = password;
Initialized = true;
mnAddInt(SendPacket, OP_VERIFY_PASSED);
mnAddInt(SendPacket, ClientNumber);
mnSendTCP(0, SendPacket, ClientNumber, false, true);
dbPrintC("Client ");
dbPrintC(dbStr(ClientNumber));
dbPrintC(" Connected As ");
dbPrint(v2);
dbPrint();
} else if (test1 == 1)
{
mnAddInt(SendPacket, OP_VERIFY_FAILED);
mnAddInt(SendPacket, clientnumber);
mnSendTCP(0, SendPacket, clientnumber, false, true);
dbPrintC("Client ");
dbPrintC(dbStr(clientnumber));
dbPrintC(" Tried To Connect As ");
dbPrintC(v1);
dbPrint(" But Failed [bad password]");
dbPrint();
}
} else if (loadok == false)
{
mnAddInt(SendPacket, OP_VERIFY_FAILED);
mnAddInt(SendPacket, clientnumber);
mnSendTCP(0, SendPacket, clientnumber, false, true);
dbPrintC("Client ");
dbPrintC(dbStr(clientnumber));
dbPrintC(" Tried To Connect As ");
dbPrintC(v2);
dbPrint(" But Failed [bad username]");
dbPrint();
}
v1[0] = '';
v2[0] = '';
}
There you all go, that should be everything needed to solve this one =/ *believe me i've been trying for some days now*
When I tried to login as the client i put "test" into the username box & "1234" into the password box, which, is a valid account.
EDIT: forgot to add the image
EDIT: EDIT: uploaded the image to the post