Esempio n. 1
0
		private static void OnRoomCreate(DuelServer server, PacketReader packet){
			string name = packet.ReadUnicode(20);
			string info = packet.ReadUnicode(20);
			string banlist=packet.ReadUnicode(50);
			GameConfig config=new GameConfig();
            config.RoomString = info;
            config.Parse(info);
			config.Name=name;
			config.BanList=banlist;
            
			Logger.Debug("OnRoomCreate:"+server.Port+","+name+"|"+info);
			lock(server.Rooms){
                server.Rooms[name] = config;
			}
            if (server.Server != null)
            {
                server.Server.server_OnRoomCreate(server, name, banlist, info);
            }
		}
Esempio n. 2
0
		private static void OnServerInfo(Client client, PacketReader reader){
			//服务器信息
			Program.Config.ChatPort = reader.ReadInt32();
			Program.Config.DuelPort = reader.ReadInt32();
			Program.Config.NeedAuth = reader.ReadBoolean();
            client.Pwd = reader.ReadUnicode(32);
#if DEBUG
			MessageBox.Show(Program.Config.ChatPort+":"+Program.Config.DuelPort+":"+Program.Config.NeedAuth + ":" + client.Pwd);
#endif
            client.OnLoginOk();
		}
Esempio n. 3
0
        private static void OnError(Client client, PacketReader reader){
			//错误
			string err = reader.ReadUnicode(256);
         //   int code = reader.ReadByte();
			MessageBox.Show(err);
			//if(!client.IsLogin){
				try{
					client.Close(client.IsLogin);
				}catch{}
			//}
		}
Esempio n. 4
0
		private static void OnRoomStart(DuelServer server, PacketReader packet){
			string name = packet.ReadUnicode(20);
			Logger.Debug("OnRoomStart:"+server.Port+","+name);
			lock(server.Rooms){
                GameConfig cfg = null;
                if(server.Rooms.TryGetValue(name, out cfg)){
                    cfg.IsStart = true;
				}else{
					Logger.Warn("no start room:"+name+" form "+server.Port);
				}
			}
			if(server.Server!=null)
				server.Server.server_OnRoomStart(server, name);
		}
Esempio n. 5
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);
					}
				}
			}
		}
Esempio n. 6
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);
			}
		}
Esempio n. 7
0
 private static void Handler(PacketReader reader)
 {
    ushort id =  reader.ReadByte();
     if(id == (ushort)RoomMessage.Info)
     {
         string name = reader.ReadUnicode(20);
         string pwd = reader.ReadUnicode(32);
         lock (Infos)
         {
             Infos[name] = pwd;
         }
     }
     reader.Close();
 }
Esempio n. 8
0
		private static void OnRoomCreate(Client client, PacketReader reader){
			//房间创建
			int port = reader.ReadInt32();
			bool needauth = reader.ReadBoolean();
			string room = reader.ReadUnicode(20);
			string banlist = reader.ReadUnicode(20);
			string info = reader.ReadUnicode(40);
			GameConfig2 config = new GameConfig2();
			config.Parse(info);
			config.Name = room;
			config.NeedAuth = needauth;
			config.DeulPort = port;
			config.BanList = banlist;
            config.RoomString = info;
            client.ServerRoomCreate(config);
		}
Esempio n. 9
0
		private static void OnClientChat(Client client, PacketReader reader){
			//大厅聊天
			string name = reader.ReadUnicode(20);
			string toname = reader.ReadUnicode(20);
			string msg = reader.ReadUnicode(256);
			client.ServerChat(name, toname, msg);
		}
Esempio n. 10
0
		private static void OnPlayerLeave(Client client, PacketReader reader){
			int port = reader.ReadInt32();
			string name = reader.ReadUnicode(20);
			string room = reader.ReadUnicode(20);
			client.ServerPlayerLeave(name, new RoomInfo(room, port));
		}
Esempio n. 11
0
		private static void OnPlayerList(Client client, PacketReader reader){
			int count = reader.ReadInt32();
			List<PlayerInfo> players=new List<PlayerInfo>();
			for(int i=0;i<count;i++){
				int port = reader.ReadInt32();
				string name = reader.ReadUnicode(20);
				string room = reader.ReadUnicode(20);
                RoomInfo r = new RoomInfo(room, port);
                PlayerInfo p = new PlayerInfo(name);
                if (!string.IsNullOrEmpty(room))
                {
                    lock (p.Rooms)
                    {
                        p.Rooms.Add(r);
                    }
                }
                players.Add(p);
			}
			client.ServerPlayerList(players);
		}
Esempio n. 12
0
		private static void OnRoomList(Client client, PacketReader reader){
			int count = reader.ReadInt32();
			List<GameConfig2> configs=new List<GameConfig2>();
			for(int i=0;i<count;i++){
                int port = reader.ReadInt32();
                bool needauth = reader.ReadBoolean();
                string name = reader.ReadUnicode(20);
				string banlist = reader.ReadUnicode(20);
				string info = reader.ReadUnicode(20);
                bool start = reader.ReadBoolean();
                GameConfig2 config =new GameConfig2();
				config.Parse(info);
				config.Name = name;
				config.BanList = banlist;
				config.DeulPort = port;
				config.NeedAuth = needauth;
                config.IsStart = start;
                config.RoomString = info;
				configs.Add(config);
			}
			client.ServerRoomList(configs);
		}
Esempio n. 13
0
		private static void OnRoomClose(Client client, PacketReader reader){
			int port = reader.ReadInt32();
			string room = reader.ReadUnicode(20);
			client.ServerRoomClose(new RoomInfo(port, room));
		}
Esempio n. 14
0
		private static void OnRoomClose(DuelServer server, PacketReader packet){
			string name = packet.ReadUnicode(20);
			Logger.Debug("OnRoomClose:"+server.Port+","+name);
			lock(server.Rooms){
				if(name == null || !server.Rooms.Remove(name)){
					Logger.Warn("no close room:"+name+" form "+server.Port);
				}
			}
			if(server.Server!=null)
				server.Server.server_OnRoomClose(server, name);
		}
Esempio n. 15
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]认证失败");
			}
		}
Esempio n. 16
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);
			}
		}
Esempio n. 17
0
		private static void OnPlayerEnter(DuelServer server, PacketReader packet){
			Logger.Debug("OnPlayerEnter:"+server.Port);
			string name = packet.ReadUnicode(20);
			string room = packet.ReadUnicode(20);
			if(server.Server!=null)
				server.Server.server_OnPlayerJoin(server, name, room);
		}