示例#1
0
		public static RoomMessage Handler(Session session, params PacketReader[] packets)
		{
			RoomMessage msg = RoomMessage.Unknown;
			foreach (PacketReader packet in packets)
			{
				//			Parse(player, packet);
				ushort id = packet.ReadByte();
				if (msg == RoomMessage.Unknown)
				{
					if (RoomMessage.IsDefined(typeof(RoomMessage), (byte)id))
					{
						msg = (RoomMessage)id;
					}
					else
					{
						Logger.Warn("unknown id:" + id);
					}
				}
				if ((session.IsLogin || session.IsClient) || (msg == RoomMessage.Info && session.Name == null) || msg == RoomMessage.PlayerInfo || msg == RoomMessage.NETWORK_CLIENT_ID)
				{
					EventHandler.Do(id, session, packet);
				}
				else
				{
					Logger.Warn("don't deal id:" + msg);
				}
				packet.Close();
				//}
			}
			return msg;
		}
示例#2
0
 public static void OnSendServerInfo(this RoomServer roomServer, Session session)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.Info);
         writer.Write(roomServer.GetChatPort());
         DuelServer srv = roomServer.GetMinServer();
         lock (srv.AsyncLock)
         {
             srv.Count++;
         }
         if (srv != null)
         {
             session.ServerInfo = srv;
             writer.Write(srv.Port);
             writer.Write(srv.NeedAuth);
         }
         else
         {
             writer.Write(0);
             writer.Write((byte)0);
         }
         writer.WriteUnicode(session.Token, 32);
         session.Send(writer.Content);
     }
 }
示例#3
0
		private static void OnChat(Session session, PacketReader packet)
		{
			string name = packet.ReadUnicode(20);
			string toname = packet.ReadUnicode(20);
			string msg = packet.ReadUnicode(256);
			if (session.Server != null)
			{
				session.Server.OnChatMessage(name, toname, msg);
			}
		}
示例#4
0
		//登录
		private static void OnInfo(Session session, PacketReader packet)
		{
			string name = packet.ReadUnicode(20);
			string pwd = packet.ReadUnicode(32);//md5
			//登录
			bool force = packet.ReadBoolean();
			if (Login(name, pwd))
			{
				session.Name = name;
				session.IsPause = false;
				//返回聊天端口,对战端口
				if (session.Server != null)
				{
					lock (session.Server.Clients)
					{
						Session old;
						if (session.Server.Clients.TryGetValue(session.Name, out old))
						{
							if (force)
							{
								old.SendError("[err]你的账号在其他地方登录");
								old.Name = "";
								//   old.Close();
							}
							else
							{
								session.IsLogin = false;
								session.IsPause = true;
								session.SendError("[err]已经登录");
								return;
							}
						}
						session.CreateToken(name, pwd);
						session.Server.SendToken(session.Name, session.Token);
						session.IsLogin = true;
						session.Server.Clients[session.Name]=session;
						session.Server.OnSendServerInfo(session);
						session.Server.server_OnPlayerJoin(session.ServerInfo, session.Name, null);
						if (!string.IsNullOrEmpty(session.Server.Tip))
						{
							session.SendServerMsg(session.Server.Tip);
						}
					}
				}
			}
			else {
				session.SendError("[err]认证失败");
			}
		}
示例#5
0
		private static void OnPlayerList(Session session, PacketReader packet)
		{
			session.OnPlayerList();
		}
示例#6
0
		private static void OnRoomList(Session session, PacketReader packet)
		{
			bool nolock = packet.ReadBoolean();
			bool nostart = packet.ReadBoolean();
			session.IsPause = false;
			if (session.Server != null)
			{
				session.Server.OnRoomList(session, nolock, nostart);
			}
		}
示例#7
0
		private static void OnRoomList2(Session session, PacketReader packet)
		{
			Logger.Debug("OnRoomList2");
			session.IsPause = false;
			if (session.Server != null)
			{
				session.Server.SendRoomList(session);
			}
		}
示例#8
0
		private static void OnClose(Session session, PacketReader packet)
		{
			session.IsPause = true;
			session.Close();
		}
示例#9
0
		private static void On302(Session session, PacketReader packet)
		{
			session.LobbyError("这是聊天室端口");
			DuelServer srv = session.Server.GetMinServer();
			session.SendMessage("这是聊天端口,随便说一句话即可和所有人聊天。");
			session.SendMessage("你的短密码是:"+session.Token+" (用户名:"+session.Name+"$"+session.Token+")");
			if (srv != null && srv.Port > 0)
			{
				session.SendMessage("推荐对战端口:" + srv.Port);
			}
			List<int> ports = session.Server.GetAllPorts();
			string msg = "所有对战端口:";
			foreach (int p in ports)
			{
				msg += p + ",";
			}
			session.SendMessage(msg);
			//  session.Close();
		}
示例#10
0
		private static void OnGameConnect(Session session, PacketReader packet)
		{
			session.IsClient = true;
			string tag = packet.ReadUnicode(20);
			string pwd = Password.GetPwd(tag);
			string name= Password.OnlyName(tag);
			session.Name =name;
			if(!Login(name, pwd)){
				session.LobbyError("Login fail");
				return;
			}
			session.CreateToken(session.Name, Password.GetPwd(tag));
			session.Server.SendToken(session.Name, session.Token);
			if (session.ip != null)
			{
				lock (session.Server.GameCliens)
				{
					if (!session.Server.GameCliens.ContainsKey(session.ip))
					{
						session.Server.GameCliens.Add(session.ip, session);
					}
				}
			}
		}
示例#11
0
		private static void OnGameChat(Session session, PacketReader packet)
		{
			session.CanGameChat = true;
			string msg = packet.ReadUnicode();
			//  Logger.Info(session.Name+":"+msg);
			if (session.Server != null && !string.IsNullOrEmpty(msg))
			{
				session.Server.OnChatMessage(session.Name, "", msg);
			}
		}
示例#12
0
 private void Listener_OnConnect(Connection<Session> Client)
 {
     if (!IsListening)
     {
         Client.Close();
         return;
     }
     Logger.Debug("Listener_OnConnect");
     Session session = new Session(Client, this);
     //分配对战端
 }
示例#13
0
        public static void OnRoomList(this RoomServer roomServer, Session session, bool nolock = false, bool nostart = false)
        {
#if DEBUG
			Logger.Debug("roomlist");
#endif
            using (PacketWriter wrtier = new PacketWriter(20))
            {
                int count = 0;
                wrtier.Write((byte)RoomMessage.RoomList);
                wrtier.Write(0);
                lock (roomServer.DuelServers)
                {
                    foreach (DuelServer srv in roomServer.DuelServers)
                    {
                        lock (srv.Rooms)
                        {
                            foreach (GameConfig config in srv.Rooms.Values)
                            {
                                count++;
                                wrtier.Write(srv.Port);
                                wrtier.Write(srv.NeedAuth);
                                wrtier.WriteUnicode(config.Name, 20);
                                wrtier.WriteUnicode(config.BanList, 20);
                                wrtier.WriteUnicode(config.RoomString, 20);
                                wrtier.Write(config.IsStart);
                            }
                        }
                    }
                }
                //重写长度
                wrtier.SetPosition(1);
                wrtier.Write(count);
                session.Send(wrtier.Content);
            }
        }
示例#14
0
        public static void SendRoomList(this RoomServer roomServer, Session session)
        {

            lock (roomServer.DuelServers)
            {
                foreach (DuelServer srv in roomServer.DuelServers)
                {
                    lock (srv.Rooms)
                    {
                        foreach (GameConfig game in srv.Rooms.Values)
                        {
                            using (PacketWriter packet = new PacketWriter(2))
                            {
                                packet.Write((ushort)RoomMessage.NETWORK_CLIENT_ID);
                                StocHostPacket hp = new StocHostPacket();
                                hp.port = (ushort)srv.Port;
                                hp.host = game.ToHostInfo();
                                hp.name = new char[20];
                                char[] name = game.HasPassword() ? game.RoomString.ToCharArray() : game.Name.ToCharArray();
                                Array.Copy(name, hp.name, Math.Min(20, name.Length));
                                if (game.IsStart)
                                {
                                    int i = 20;
                                    while (--i > 4) hp.name[i] = hp.name[i - 5];
                                    hp.name[0] = '【';
                                    hp.name[1] = '对';
                                    hp.name[2] = '战';
                                    hp.name[3] = '中';
                                    hp.name[4] = '】';
                                }
                                packet.Write(StructTransformer.StructToBytes(hp));
                                session.Send(packet.Content, false);
                            }
                        }
                    }
                    session.PeekSend();
                }
            }

        }