예제 #1
0
        static public void SendFireHandler(NetConnection connection, object data)
        {
            FireData fire = null;

            try
            {
                fire = GSrv.Deserialize <FireData>((byte[])data);
            }
            catch
            {
                return;
            }

            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            if (PlayerCaches.InLobby(connection))
            {
                return;
            }

            int roomid = PlayerCaches.GetRoomID(connection);

            if (Lobby.GetRoomState(roomid) == 0)
            {
                return;
            }

            Lobby.ReplyFire(connection, roomid, fire);
        }
예제 #2
0
        public static void LeaveRoom(NetConnection connection, int roomid)
        {
            Player player = rooms[roomid].LeaveRoom(connection);

            players.Add(connection, player);
            PlayerCaches.BackToLobby(connection);
        }
예제 #3
0
        static public void LeaveRoomHandler(NetConnection connection, object data)
        {
            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            if (PlayerCaches.InLobby(connection))
            {
                return;
            }

            int roomid = PlayerCaches.GetRoomID(connection);

            if (Lobby.GetRoomState(roomid) == 1)
            {
                return;
            }

            Lobby.LeaveRoom(connection, roomid);
            Lobby.SendRoomStateToAll(roomid);

            Lobby.CheckBattleStart(roomid);

            GSrv.Send(MessageType.ReplySuccessLeaveRoom, connection, NetDeliveryMethod.ReliableOrdered);
            LobbyState state = Lobby.GetLobbyState();

            GSrv.Send(MessageType.ReplyLobbyState, GSrv.Serialize <LobbyState>(state), connection, NetDeliveryMethod.ReliableOrdered);
        }
예제 #4
0
        static public void EnterRoomHandler(NetConnection connection, object data)
        {
            int roomid = (int)data;

            if (roomid < 0 || Env.RoomNum <= roomid)
            {
                return;
            }

            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            if (!PlayerCaches.InLobby(connection))
            {
                return;
            }

            if (Lobby.GetRoomState(roomid) == 1)
            {
                return;
            }

            Lobby.EnterRoom(connection, roomid);

            GSrv.Send(MessageType.ReplySuccessEnterRoom, connection, NetDeliveryMethod.ReliableOrdered);

            Lobby.SendRoomStateToAll(roomid);
        }
예제 #5
0
        static public void PushHandler(NetConnection connection, object data)
        {
            PushData push = null;

            try
            {
                push = GSrv.Deserialize <PushData>((byte[])data);
            }
            catch
            {
                return;
            }

            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            if (PlayerCaches.InLobby(connection))
            {
                return;
            }

            int roomid = PlayerCaches.GetRoomID(connection);

            if (Lobby.GetRoomState(roomid) == 0)
            {
                return;
            }

            Lobby.Push(connection, roomid, push);
        }
예제 #6
0
        static public void DisconnectHandler(NetConnection connection, object data)
        {
            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            Lobby.Disconnect(connection);
        }
예제 #7
0
        public static int AddPlayer(NetConnection connection, string username)
        {
            Player player = new Player(connection, username);

            players.Add(connection, player);

            PlayerCaches.AddPlayerCache(connection);

            return(player.userid);
        }
예제 #8
0
        public static void Disconnect(NetConnection connection)
        {
            if (PlayerCaches.InLobby(connection))
            {
                Console.WriteLine("Leave:" + players[connection].username);
                players.Remove(connection);
            }
            else
            {
                int roomid = PlayerCaches.GetRoomID(connection);
                rooms[roomid].Disconnect(connection);
            }

            PlayerCaches.Disconnect(connection);
        }
예제 #9
0
        public void EnterRoom(Player player)
        {
            int blueCount = players.Where(x => x.Value.faction == 0).ToArray().Length;
            int redCount  = players.Where(x => x.Value.faction == 1).ToArray().Length;

            if (blueCount > redCount)
            {
                player.faction = 1;
            }
            else
            {
                player.faction = 0;
            }

            player.ready = false;

            players.Add(player.connection, player);
            PlayerCaches.EnterRoom(player.connection, roomid);
        }
예제 #10
0
        static public void SetBlockHandler(NetConnection connection, object data)
        {
            BlockData block = null;

            try
            {
                block = GSrv.Deserialize <BlockData>((byte[])data);
            }
            catch
            {
                return;
            }

            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            if (PlayerCaches.InLobby(connection))
            {
                return;
            }

            int roomid = PlayerCaches.GetRoomID(connection);

            if (Lobby.GetRoomState(roomid) == 0)
            {
                return;
            }

            if (!Env.IsInsideWorld(block.x, block.y, block.z))
            {
                return;
            }

            if (Env.IsCorePos(block.x, block.y, block.z))
            {
                return;
            }

            Lobby.ReplySetBlock(roomid, block);
        }
예제 #11
0
        static public void TouchCoreHandler(NetConnection connection, object data)
        {
            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            if (PlayerCaches.InLobby(connection))
            {
                return;
            }

            int roomid = PlayerCaches.GetRoomID(connection);

            if (Lobby.GetRoomState(roomid) == 0)
            {
                return;
            }

            Lobby.TouchCore(connection, roomid);
        }
예제 #12
0
        static public void ChangeFactionHandler(NetConnection connection, object data)
        {
            if (!PlayerCaches.AuthDone(connection))
            {
                return;
            }

            if (PlayerCaches.InLobby(connection))
            {
                return;
            }

            int roomid = PlayerCaches.GetRoomID(connection);

            if (Lobby.GetRoomState(roomid) == 1)
            {
                return;
            }

            Lobby.ChangeFaction(connection, roomid);
            Lobby.SendRoomStateToAll(roomid);
        }
예제 #13
0
        static public void SendUserNameHandler(NetConnection connection, object data)
        {
            string username = (string)data;

            if (username == "")
            {
                username = "******";
            }

            if (PlayerCaches.AuthDone(connection))
            {
                return;
            }

            Console.WriteLine("Enter:" + username);

            int userid = Lobby.AddPlayer(connection, username);

            GSrv.Send(MessageType.ReplyUserID, userid, connection, NetDeliveryMethod.ReliableOrdered);
            LobbyState state = Lobby.GetLobbyState();

            GSrv.Send(MessageType.ReplyLobbyState, GSrv.Serialize <LobbyState>(state), connection, NetDeliveryMethod.ReliableOrdered);
        }