I assign the player.id both Client and Server Side so they match up.
Stated in Case: Packet.LoginRequest in GameServer.CS
if (!string.IsNullOrEmpty(sessionID))
{
player.id = userID;
player.name = user;
}
MysqlFunctions.CheckIfPlayerAlreadyInSession(userID); Returns a GUID string to and creates a session ID for authentication during gameplay ONLY if there isn't already one for the user, which is why it takes in an (int) as a parameter (userID). If there is already a session created then the user is already logged in and returns an empty string so two accounts can't be logged in at the same time. I change the player.id to the user id and player name to the player's username here so i don't have to request another packet request for a name change, which ultimately does the exact same thing. The packet is returned successfully because the player does get logged in successfully as shown in my screenshots.
But obviously I have to do the same thing client side but only if there wasn't an error during the login proccess, which my "LoginRequest" Packet Case Statement checks for (invalid credentials or a sesionID already given to a player, which are errorcode 1 and 2 respectfully). My LoginHandler checks for ushort errorcode and if errorcode != 0 then there was an error during the login proccess. On the client this displays text for an NGUI Label "Incorrect Login Credentials" or "User is already Logged in by a another player" an executes GameManager2.EndNow(). But if it was successful it sets the player ID and name as it did on the server side.
TNManager.player.id = uid;
TNManager.player.name = GameManager2.instance.Username;
If the player.id is truly more depended on by other methods and functions, I can reference the player's user account by adding a userID as a parameter of all my packet sending functions although it is definitely not ideal. It's much easier and more optimal to link the player.id directly to their username id on login because i can just pass the player.id into my MySQL functions as a parameter when a request packet is made instead of passing the username id as an extra parameter in every request packet.
But if i have to do it that way than it is what it is.
As for TManager.LoadLevel, This is only supposed to be used when it affects every player in the room and only works when a player is in a channel. I'm simply just changing scenes locally in the client to the "character selection screen" where the player select they're character, but they're still connected to the server and can send/receive packets. When they've selected they're character then they join channel 1 which I've deemed the "General" Channel in my custom chat. TNet is going to be primarily used for sending packets which execute mysql queries and request data based on players to individual user clients more than syncing with other players. It will sync with other players for chat purposes and an updated player character stat list so all players see the same data. I don't think i'll ever be using TManager.LoadLevel for the purposes of changing a scene for an entire group of players in the same channel. Unless i'm misinterpreting TManager.LoadLevel's purpose.
I really do appreciate you're help. I'm going to make some changes to my packets and not switch the player Id when the user logs in. Come to think of it, it would actually be smarter and more secure to use the sessionID to reference the player in my sessions table and grab the userID from there for mysql queries, so i'll give that a try and see if that changes anything. Let me know if you see anything else I should take a look at that might be causing the problem. I'll update my post if anything changes before you get back to me.
Cheers! and Best Regards,
-Monkey Man