public static CtosMessage Handler(GameSession player, params GameClientPacket[] packets)
        {
            CtosMessage firstmsg = CtosMessage.Unknown;

            if (packets == null || packets.Length == 0)
            {
                return(firstmsg);
            }
            foreach (GameClientPacket packet in packets)
            {
                //			Parse(player, packet);
                if (packet.Length == 0)
                {
                    continue;
                }
                CtosMessage msg = packet.ReadCtos();
                if (firstmsg == CtosMessage.Unknown)
                {
                    firstmsg = msg;
                }
                if (msg == CtosMessage.CreateGame || msg == CtosMessage.JoinGame || msg == CtosMessage.PlayerInfo)
                {
                }
                else
                {
                    if (!player.IsAuthentified)
                    {
                        Logger.Warn("auth error:" + player.Name);
                        player.CloseAsync();
                        break;
                    }
                    if (player.Type == (int)PlayerType.Undefined)
                    {
                        Logger.Warn("player type error:" + player.Name);
                        player.CloseAsync();
                        break;
                    }
                }
                if (player.Game != null)
                {
                    lock (player.Game.AsyncRoot){
                        EventHandler.Do((ushort)msg, player, packet);
                    }
                }
                else
                {
                    EventHandler.Do((ushort)msg, player, packet);
                }
                packet.Close();
            }
            return(firstmsg);
        }
 public static void OnClose(GameSession client, GameClientPacket packet)
 {
     using (PacketWriter packet_write = new PacketWriter(GameServerPacket.GamePacketByteLength)) {
         packet_write.Write((byte)RoomMessage.STOP_CLIENT);
         client.Send(packet_write.Content);
     }
     client.CloseAsync();
 }
Example #3
0
		public static CtosMessage Handler(GameSession player, params GameClientPacket[] packets){
			CtosMessage firstmsg = CtosMessage.Unknown;
			if(packets == null || packets.Length == 0) 
				return firstmsg;
			foreach(GameClientPacket packet in packets){
				//			Parse(player, packet);
				if(packet.Length==0){
					continue;
				}
				CtosMessage msg = packet.ReadCtos();
				if(firstmsg == CtosMessage.Unknown){
					firstmsg = msg;
				}
				if(msg == CtosMessage.CreateGame || msg == CtosMessage.JoinGame || msg == CtosMessage.PlayerInfo){
					
				}else{
					if(!player.IsAuthentified){
						Logger.Warn("auth error:"+player.Name);
						player.CloseAsync();
						break;
					}
					if(player.Type == (int)PlayerType.Undefined){
						Logger.Warn("player type error:"+player.Name);
						player.CloseAsync();
						break;
					}
				}
				if(player.Game!=null){
					lock(player.Game.AsyncRoot){
						EventHandler.Do((ushort)msg, player, packet);
					}
				}else{
					EventHandler.Do((ushort)msg, player, packet);
				}
				packet.Close();
			}
			return firstmsg;
		}
        public static void OnCreateGame(GameSession client, GameClientPacket packet)
        {
            if (string.IsNullOrEmpty(client.Name) || client.Type != (int)PlayerType.Undefined)
            {
                return;
            }
            GameRoom room = null;

            byte[]         data = packet.ReadBytes(StructTransformer.SizeOf(typeof(CtosCreateGame)));
            CtosCreateGame roomconfig;
            GameConfig     config = null;

            try
            {
                roomconfig = (CtosCreateGame)StructTransformer.BytesToStruct(data, typeof(CtosCreateGame));
                config     = roomconfig.Build();
            }
            catch (Exception e)
            {
                Logger.Warn(e);
            }
            if (config == null)
            {
                client.CloseAsync();
                return;
            }
            room = RoomManager.CreateOrGetGame(config);

            if (room == null)
            {
                client.LobbyError(Messages.MSG_FULL);
                return;
            }
            client.Game = room;
            lock (room.AsyncRoot)
            {
                room.AddPlayer(client);
            }
            //IsAuthentified = CheckAuth();
            if (!client.IsAuthentified)
            {
                client.LobbyError(Messages.ERR_AUTH_FAIL);
            }
        }
 public static void OnLeaveGame(GameSession client, GameClientPacket packet)
 {
     client.CloseAsync();
 }
Example #6
0
		public static void OnLeaveGame(GameSession client, GameClientPacket packet){
            client.CloseAsync();
		}
Example #7
0
 public static void OnClose(GameSession client, GameClientPacket packet)
 {
     using (PacketWriter packet_write = new PacketWriter(GameServerPacket.GamePacketByteLength)) {
         packet_write.Write((byte)RoomMessage.STOP_CLIENT);
         client.Send(packet_write.Content);
     }
     client.CloseAsync();
 }
Example #8
0
		public static void OnCreateGame(GameSession client, GameClientPacket packet){
			if (string.IsNullOrEmpty(client.Name) || client.Type != (int)PlayerType.Undefined)
				return;
			GameRoom room = null;
            byte[] data = packet.ReadBytes(StructTransformer.SizeOf(typeof(CtosCreateGame)));
            CtosCreateGame roomconfig;
            GameConfig config = null;
            try
            {
                roomconfig = (CtosCreateGame)StructTransformer.BytesToStruct(data, typeof(CtosCreateGame));
                config = roomconfig.Build();
            }
            catch(Exception e)
            {
                Logger.Warn(e);
            }
            if (config == null)
            {
                client.CloseAsync();
                return;
            }
			room = RoomManager.CreateOrGetGame(config);

			if (room == null)
			{
				client.LobbyError(Messages.MSG_FULL);
				return;
			}
			client.Game = room;
            lock (room.AsyncRoot)
            {
                room.AddPlayer(client);
            }
			//IsAuthentified = CheckAuth();
			if(!client.IsAuthentified){
				client.LobbyError(Messages.ERR_AUTH_FAIL);
			}
		}