Beispiel #1
0
        private static void ReceiveName(SocketState state)
        {
            StringBuilder sb = new StringBuilder();

            string playerName = state.sb.ToString();// Get playername

            string playerName2 = Regex.Replace(playerName.Trim(), @"\t|\n|\r", "");


            //the if else statments are just to show that the controls are working

            GetInputs(state);
            state.sb.Clear();

            if (playerName2.Length > 1 && !playerName.Contains("("))
            {
                lock (Clients) // Adding clients to list
                {
                    Clients.Add(state);
                }
                //Calls for Assign ID and allows asssignID to increment to give a unique ID
                AssignID();
                //create a random ship for player with the ID and name
                Ship s = RandomShipGen(ID, playerName2);
                //add it to the world dictionry for ships

                lock (world.GetShips())
                {
                    world.GetShips().Add(s.GetID(), s);
                }
                sb.Append(ID + "\n" + UniverseSize);

                //seeing tokens

                string final = sb.ToString();

                //sends the intial startup

                Networking.SendData(state.theSocket, final);
            }

            //upon recieving the name, send the startup data
            //the server must not send any wold data to a client before sending the startup data.
        }