コード例 #1
0
        /// <summary>
        /// This methods recieves the name and does the first handshake with the
        /// client.
        /// </summary>
        /// <param name="ss"></param>
        public static void RecieveName(SocketState ss)
        {
            string name = "";

            //totalData uses string builder to store all the string from the ss.
            string totalData = ss.sb.ToString();

            //this method splits totalData by nextline.
            String[] parts = totalData.Split('\n');
            //the first string sent is the players name.
            name = parts[0];
            Ship ship;

            //lock the world
            lock (world)
            {
                //calls generate new ship from world and sets it to ship.
                ship = world.generatenewShip(name);
                //sets ss.ID to ships id.
                ss.setSocketStateID(ship.getShipId());
            }

            ss.callMe = callBack;

            //lock the list and add the socketstate.
            lock (list)
            {
                list.Add(ss);
            }
            int universe = UniverseSize;

            //removes the name from the socketstate.
            ss.sb.Remove(0, parts[0].Length + 1);
            //sends data to the specific socket.
            Networking.Send(ss.theSocket, ss.ID.ToString() + "" + "\n" + universe + "\n");
            //calling get data to get more data.
            Networking.GetData(ss);
        }