示例#1
0
        public void ClientJoined(S server, Connection newConn)
        {
            var defaults = new GameRules.PlayerSettings();

            var client = new Session.Client()
            {
                Index = newConn.PlayerIndex,
                Color1 = defaults.Color1,
                Color2 = defaults.Color2,
                Name = defaults.Name,
                Country = "random",
                State = Session.ClientState.NotReady,
                SpawnPoint = 0,
                Team = 0,
                Slot = ChooseFreeSlot(server),
            };

            var slotData = server.lobbyInfo.Slots.FirstOrDefault( x => x.Index == client.Slot );
            if (slotData != null)
                SyncClientToPlayerReference(client, server.Map.Players[slotData.MapPlayer]);

            server.lobbyInfo.Clients.Add(client);

            Log.Write("server", "Client {0}: Accepted connection from {1}",
                newConn.PlayerIndex, newConn.socket.RemoteEndPoint);

            server.SendChat(newConn, "has joined the game.");
            server.SyncLobbyInfo();
        }
示例#2
0
文件: Server.cs 项目: subspace/OpenRA
        static void AcceptConnection()
        {
            var newConn = new Connection { socket = listener.AcceptSocket() };
            try
            {
                if (GameStarted)
                {
                    Log.Write("server", "Rejected connection from {0}; game is already started.",
                        newConn.socket.RemoteEndPoint);
                    newConn.socket.Close();
                    return;
                }

                newConn.socket.Blocking = false;
                newConn.socket.NoDelay = true;

                // assign the player number.
                newConn.PlayerIndex = ChooseFreePlayerIndex();
                newConn.socket.Send(BitConverter.GetBytes(ProtocolVersion.Version));
                newConn.socket.Send(BitConverter.GetBytes(newConn.PlayerIndex));
                conns.Add(newConn);

                var defaults = new GameRules.PlayerSettings();
                lobbyInfo.Clients.Add(
                    new Session.Client()
                    {
                        Index = newConn.PlayerIndex,
                        Color1 = defaults.Color1,
                        Color2 = defaults.Color2,
                        Name = defaults.Name,
                        Country = "random",
                        State = Session.ClientState.NotReady,
                        SpawnPoint = 0,
                        Team = 0,
                        Slot = ChooseFreeSlot(),
                    });

                Log.Write("server", "Client {0}: Accepted connection from {1}",
                    newConn.PlayerIndex, newConn.socket.RemoteEndPoint);

                SendChat(newConn, "has joined the game.");

                SyncLobbyInfo();
            }
            catch (Exception e) { DropClient(newConn, e); }
        }