/*: it is important that the server sends the startup info before adding the client to the list of all clients. * This guarantees that the startup info is sent before any world info. Remember that the server is running a timer that may send world info to the list of clients at any time. */ /// <summary> /// /// </summary> /// <param name="state"></param> private static void ReceiveName(NetworkController.SocketState state) { // Socket getData = state.theSocket; state.callBack = (SendStartUp); Console.WriteLine(state.getID()); //This will only work for testing the FIRST client. We will have to change to something that determines the name among other possible messages..... string name = state.sb.ToString(); //create the new player and add him to the world. Snake player; //Locking this up to try and fix race cond lock (world) { player = world.AddNewSnake(name); } state.setID(player.getID()); SendStartUp(state); // Console.WriteLine(name); //Also locking to fix bug with two clients trying to connect. lock (connectedClients) { connectedClients.AddLast(state); } // Console.WriteLine(state.getID()); //Again, will have to change this to send player specific ID. NetworkController.NetworkHandler.AwaitDataFromServer(state); }