Ejemplo n.º 1
0
        void SendCurrentStatus()
        {
            if (playersInRoom == null || Room == null)
            {
                return;
            }

            if (Environment.TickCount > lastUpdate)
            {
                lastUpdate = Environment.TickCount + 1000;

                var sendMsg = UsingPeer.CreateMessage()
                              .Start(Constants.MESSAGETYPE.OUTGAME);
                sendMsg.Write(Constants.OUTGAME.UPDATE_GAMEINFO);
                sendMsg.Write((byte)currentGameState);
                sendMsg.Write(WantedScheme);
                sendMsg.Write((short)playersInRoom.Count);
                foreach (var player in playersInRoom)
                {
                    sendMsg.Write(player.Value);
                }

                if (GetUserConnections().Count > 0)
                {
                    UsingPeer.SendMessage(sendMsg, GetUserConnections(), Lidgren.Network.NetDeliveryMethod.ReliableOrdered, 1);
                }
            }
        }
Ejemplo n.º 2
0
        void CheckPlayerEntities()
        {
            // Je ne crée pas d'allocation pour le GC si il n y a pas besoin d'enlever des joueurs
            List <string> playersToRemove = null;

            foreach (var player in playersInRoom)
            {
                if (!usersInRoom.ContainsValue(player.Value.User))
                {
                    if (playersToRemove == null)
                    {
                        playersToRemove = new List <string>();
                    }

                    playersToRemove.Add(player.Key);

                    if (!player.Value.isBot)
                    {
                        var sendMsg = UsingPeer.CreateMessage("HEADER");
                        sendMsg.Write(Constants.MESSAGETYPE.SYSTEM);
                        sendMsg.Write(Constants.SYSTEM.SHARE_USERDISCONNECT_FROM_ROOM);
                        sendMsg.Write(player.Value.User.login);
                    }

                    player.Value.GetOwnedActors()
                    .ForEach(actor => actor.Destroy());
                    continue;
                }

                if (entitySystem.Actors.Exist("playerMain_main:" + player.Value.User.login))
                {
                }
                else
                {
                    EntityBaseActor actor = null;
                    (actor = entitySystem.CreateActor <EntityBaseActor>("playerMain_main:" + player.Value.User.login, true))
                    .SetActive(true);
                    actor.Owner = player.Value;
                }

                if (player.Value.GetManager() == null)
                {
                    player.Value.SetManager();
                }
            }

            if (playersToRemove != null)
            {
                foreach (var playerLogin in playersToRemove)
                {
                    playersInRoom.Remove(playerLogin);
                }
            }
        }