I am trying to check if in my 32 players multiplayer game the same account log twice, for some misterious reasons I am failing to do such a simple thing, both client side checks and server side checks.
CLIENT SIDE
I am trying to compare the username of the player to every player logged in the server, before to chose the slot to take, both lowered, here's the code.
rem controlla se player già loggato
if file exist(cartellaGioco$ + "List.txt")=0
open to write 1, cartellaGioco$ + "List.txt"
else
delete file cartellaGioco$ + "List.txt"
open to write 1, cartellaGioco$ + "List.txt"
endif
for x=0 to 31
UsernameLowered$= LOWER$(Username$)
SlotPlayerLowered$= LOWER$(SlotsPlayersName$(x))
if UsernameLowered$ = SlotPlayerLowered$
DialogoMenuStato$= "DoubleLogs"
write string 1, UsernameLowered$ + " = " + SlotPlayerLowered$
else
write string 1, UsernameLowered$ + " != " + SlotPlayerLowered$
endif
next x
write string 1, "DialogoMenuStato$= " + DialogoMenuStato$
close file 1
So here the problem is, randomly it fails to compare the username to the other players, even if the name is EXACTLY the same (both strings are lowered).
As you can see from my code I am also doing some logging to understand what is going on, and this is the result printed on the file:
playertest != playertest
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
playertest != empty
DialogoMenuStato$= MultiplayerScegliSlot
How can it be playertest different from playertest ???
The weird thing is that if I try to do a separated small test it seems to work, but there is no reason to make a difference as I print out on file all the maths and no way that playertest could be different than playertest!
SERVER SIDE
This is the serverside part (only the part related to the slot assignement) that check if the player is already logged (same as client, lowers both strings to compare them)
// Player Request Slot
elseif ($message == 'RequestSlot')
{
// Data passed from player
$UsernameToAdd= strtok($message,'@');
$SlotChosen= strtok('@');
$UsernameIP= strtok('@');
// Check if slot is empty
if ($Giocatori[$SlotChosen] == "*")
{
// Check if player already logged
$GiocatoreGiaLoggato=0;
$UsernameToAddLower= strtolower ($UsernameToAdd);
for ($x=0; $x < 32; $x++)
{
$GiocatoriLower= strtolower ($Giocatori[$x]);
if ($GiocatoriLower == $UsernameToAddLower)
$GiocatoreGiaLoggato=1;
}
if ($GiocatoreGiaLoggato == 1)
{
$output= "UserLogged@";
}
else
{
// Everything ok, assign player to slot
$Giocatori[$SlotChosen]= $UsernameToAdd;
$tempo= microtime(0);
$tempoMem= substr($tempo,10,strlen($tempo)-1);
$GiocatoriTimer[$SlotChosen]= $tempoMem + 30;
$GiocatoriIP[$SlotChosen]= $UsernameIP;
$GiocatoriCounter[$SlotChosen]= 0;
$output= "SlotOk";
$output .= "@" . $ServerName;
}
}
else
{
$output= "SlotRefused@";
}
// Avoid memory leaks
unset($message);
strtok('', '');
// Send output to player
socket_sendto($socket, $output, strlen($output) , 0 , $remote_ip , $remote_port);
}
I have fixed and found workarounds for things much complex than this and now I fall for a simple string comparison, what am I doing wrong?
Just one of these 2 checks should be enough "client or server" but I can't manage to work none of them.