Beispiel #1
0
        private void PlayerNameMessage(GlobalPlayer player, NetworkMessage msg)
        {
            string newName = msg.GetString();

            player.Name = newName;
            Logger.WriteLine("Player {0} changed its name to {1}", player.Id, newName);

            var writer = new NetworkWriter(GlobalProtocol.ServerToClient.PlayerNameChanged);

            player.SendWriter(writer, DeliveryMethod.ReliableOrdered);
        }
Beispiel #2
0
        private void ConnectToRoomMessage(GlobalPlayer player, NetworkMessage msg)
        {
            bool spectator = msg.GetBool();

            GameInstance tojoin = null;

            if (spectator)
            {
                int roomID = msg.GetInt();
                if (!Rooms.ContainsKey(roomID))
                {
                    return;
                }
                tojoin = Rooms[roomID];
            }
            else
            {
                foreach (var room in Rooms)
                {
                    if (room.Value.Joinable)
                    {
                        tojoin = room.Value;
                        break;
                    }
                }

                if (tojoin == null)
                {
                    tojoin = new GameInstance(this);
                    Rooms.Add(tojoin.Id, tojoin);
                }
            }

            player.IsSpectator = spectator;
            tojoin.AddExpectedPlayer(player);

            NetworkWriter writer = new NetworkWriter(GlobalProtocol.ServerToClient.ConnectToRoom);

            writer.Put(tojoin.ListenPort);
            player.SendWriter(writer, DeliveryMethod.ReliableOrdered);
        }