Example #1
0
		public static void OnRoomEvent(this GameServer server, StoSMessage msg, RoomInfo info){
			using(PacketWriter writer = new PacketWriter(2)){
				writer.Write((ushort)msg);
				//length
				writer.Write((ushort)1);
				writer.WriteUnicode(info.Name, 20);
				writer.WriteUnicode(info.Pwd, 20);
				writer.Write((byte)info.Rule);
				writer.Write((byte)info.Mode);
				writer.Write(info.IsStart);
				writer.WriteUnicode(info.Lflist, 60);
				writer.Write(info.Warring);
				writer.Write(info.StartLP);
				writer.Write((ushort)info.players.Length);
				for(int i =0; i<info.players.Length;i++){
					writer.WriteUnicode(info.players[i], 20);
				}
				writer.Write((ushort)info.observers.Count);
				for(int i =0; i<info.observers.Count;i++){
					writer.WriteUnicode(info.observers[i], 20);
				}
				//string str = Tool.ToJson(info);
				//byte[] bs = Encoding.Unicode.GetBytes(str);
				//writer.Write(bs);
				writer.Use();
				//Send(server.LocalClient, writer.Content);
			}
		}
Example #2
0
		public static void OnPlayerLeave(GameSession player, GameRoom room){
            if (player.Name == null || player.Name.StartsWith("[AI]")) return;
            using (PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.PlayerLeave);
				writer.WriteUnicode(player.Name, 20);
				writer.WriteUnicode(room.Config.Name, 20);
				Send(writer.Content);
			}
		}
Example #3
0
		public static void OnPlayerEnter(GameSession player, GameRoom room){
            if (player.Name==null||player.Name.StartsWith("[AI]")) return;
			using(PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.PlayerEnter);
				writer.WriteUnicode(player.Name, 20);
				writer.WriteUnicode(room.Config.Name, 20);
				Send(writer.Content);
			}
			string tip = Messages.RandomMessage();
			if(!string.IsNullOrEmpty(tip))
				player.ServerMessage(Messages.RandomMessage());
		}
Example #4
0
		public static void OnRoomCreate(GameRoom room){
			if(room==null||room.Config==null){
				return;
			}
			using(PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.RoomCreate);
				writer.WriteUnicode(room.Name, 20);
				writer.WriteUnicode(room.Config.Name, 20);
				writer.WriteUnicode(room.Config.BanList);
				Send(writer.Content);
			}
		}
Example #5
0
		public static void OnRoomClose(GameRoom room){
            using (PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.RoomClose);
				writer.WriteUnicode(room.Config.Name, 20);
				Send(writer.Content);
			}
		}
Example #6
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);
     }
 }
Example #7
0
 public static void OnPlayerList(this Session client)
 {
     lock (client.Server.Clients)
     {
         using (PacketWriter writer = new PacketWriter(2))
         {
             writer.Write((byte)RoomMessage.PlayerList);
             writer.Write(client.Server.Clients.Count);
             foreach (Session session in client.Server.Clients.Values)
             {
                 writer.Write(session.ServerInfo == null ? 0 : session.ServerInfo.Port);
                 writer.WriteUnicode(session.Name, 20);
                 writer.WriteUnicode(session.RoomName, 20);
             }
             client.Send(writer.Content);
         }
     }
 }
Example #8
0
        public static void OnChatMessage(this RoomServer roomServer, string name, string toname, string msg)
        {
            using (PacketWriter writer = new PacketWriter(2))
            {
                writer.Write((byte)RoomMessage.OnChat);
                writer.Write((short)0x11);
                writer.WriteUnicode(name + ":" + msg);
                if (string.IsNullOrEmpty(toname))
                {
                    Logger.Debug("send to client");
                    roomServer.SendAllClient(writer.Content, name: name);
                }
            }
            using (PacketWriter writer = new PacketWriter(2))
            {
                writer.Write((byte)RoomMessage.Chat);
                writer.WriteUnicode(name, 20);
                writer.WriteUnicode(toname, 20);
                writer.WriteUnicode(msg, msg.Length + 1);
                if (!string.IsNullOrEmpty(toname))
                {
                    lock (roomServer.Clients)
                    {
                        Session sender = null;
                        if (roomServer.Clients.TryGetValue(name, out sender))
                        {
                            sender.Send(writer.Content, true);
                        }
                        else
                        {
#if DEBUG
							Console.WriteLine("no find "+name);
#endif
                        }
                        if (name != toname)
                        {
                            Session recevicer = null;
                            if (roomServer.Clients.TryGetValue(toname, out recevicer))
                            {
                                recevicer.Send(writer.Content, true);
                            }
                            else
                            {
                                if (sender != null)
                                {
                                    sender.SendError("[err]" + toname + " 不在线。");
                                }
#if DEBUG
								Console.WriteLine("no find "+toname);
#endif
                            }
                        }
                    }
                }
                else
                {
                    roomServer.SendAll(writer.Content, true, true);
                }
            }
        }
Example #9
0
 /// <summary>
 /// 发送聊天消息
 /// </summary>
 public bool OnChat(string msg, bool hidename, string toname = "")
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.Chat);
         if (string.IsNullOrEmpty(toname))
         {
             if (hidename)
             {
                 if (random.Next(100) < 10)
                 {
                     writer.WriteUnicode("[匿名]"+ Name, 20);
                 }
                 else {
                     //90%匿名
                     writer.WriteUnicode("[匿名]", 20);
                 }
             }
             else {
                 writer.WriteUnicode(Name, 20);
             }
         }
         else {
             writer.WriteUnicode(Name, 20);
         }
         writer.WriteUnicode(toname, 20);
         writer.WriteUnicode(msg, msg.Length + 1);
         Send(writer.Content);
     }
     return false;
 }
Example #10
0
 /// <summary>
 /// 联网登录
 /// </summary>
 public void Login(string name, string pwd,bool force = false)
 {
     Name = name;
     //Pwd = pwd;
     pwd = Tool.GetMd5(pwd);
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.Info);
         writer.WriteUnicode(Name, 20);
         writer.WriteUnicode(pwd, 32);
         writer.Write(force);
         Send(writer.Content);
     }
 }
Example #11
0
 public static void SendServerMsg(this Session session, string msg)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.Chat);
         writer.WriteUnicode("", 20);
         writer.WriteUnicode("", 20);
         writer.WriteUnicode(msg, msg.Length + 1);
         session.Send(writer);
     }
 }
Example #12
0
		public static void LobbyError(this Session session, string message)
		{
			using (PacketWriter join = new PacketWriter(2))
			{
				join.Write((byte)RoomMessage.JoinGame);
				join.Write(0U);
				join.Write((byte)0);
				join.Write((byte)0);
				join.Write(0);
				join.Write(0);
				join.Write(0);
				// C++ padding: 5 bytes + 3 bytes = 8 bytes
				for (int i = 0; i < 3; i++)
					join.Write((byte)0);
				join.Write(0);
				join.Write((byte)0);
				join.Write((byte)0);
				join.Write((short)0);
				session.Send(join, false);
			}

			using (PacketWriter enter = new PacketWriter(2))
			{
				enter.Write((byte)RoomMessage.HsPlayerEnter);
				enter.WriteUnicode("[err]" + message, 20);
				enter.Write((byte)0);
				session.Send(enter);
			}
		}
Example #13
0
 public void SendToken(string name, string tk)
 {
     using (PacketWriter token = new PacketWriter(2))
     {
         token.Write((byte)RoomMessage.Info);
         token.WriteUnicode(name, 20);
         token.WriteUnicode(tk, 32);
         lock (DuelServers)
         {
             foreach(DuelServer srv in DuelServers)
             {
                 srv.Send(token);
             }
         }
     }
 }
Example #14
0
 public static void server_OnRoomClose(this RoomServer roomServer, DuelServer server, string name)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.RoomClose);
         writer.Write(server.Port);
         writer.WriteUnicode(name, 20);
         roomServer.SendAll(writer.Content);
     }
 }
Example #15
0
 public static void server_OnRoomCreate(this RoomServer roomServer, DuelServer server, string name, string banlist, string gameinfo)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.RoomCreate);
         writer.Write(server.Port);
         writer.Write(server.NeedAuth);
         writer.WriteUnicode(name, 20);
         writer.WriteUnicode(banlist, 20);
         writer.WriteUnicode(gameinfo, gameinfo.Length + 1);
         //start duel
         writer.Write(false);
         roomServer.SendAll(writer.Content);
     }
 }
Example #16
0
 public static void SendError(this Session session, string err)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.Error);
         writer.WriteUnicode(err, err.Length + 1);
         session.Send(writer.Content);
     }
 }
Example #17
0
 public static void OnError(this RoomServer roomServer, string err)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.Error);
         writer.WriteUnicode(err, err.Length + 1);
         roomServer.SendAll(writer.Content);
     }
 }
Example #18
0
		private static void SendMessage(this Session session, string msg)
		{
			using (PacketWriter chat = new PacketWriter(2))
			{
				chat.Write((byte)RoomMessage.OnChat);
				//PlayerType.Yellow
				chat.Write((short)0x10);
				chat.WriteUnicode(msg);
				session.Send(chat);
			}
		}
Example #19
0
        public static void server_OnPlayerLeave(this RoomServer roomServer, DuelServer server, string name, string room)
        {
            if (server != null && string.IsNullOrEmpty(room))
            {
                lock (server.AsyncLock)
                {
                    server.Count--;
                }
            }
            if (string.IsNullOrEmpty(name)) return;

            lock (roomServer.Clients)
            {
                Session player = null;
                if (roomServer.Clients.TryGetValue(name, out player))
                    player.RoomName = null;
            }
            using (PacketWriter writer = new PacketWriter(2))
            {
                writer.Write((byte)RoomMessage.PlayerLeave);
                writer.Write(server == null ? 0 : server.Port);
                writer.WriteUnicode(name, 20);
                writer.WriteUnicode(room, 20);
                roomServer.SendAll(writer.Content);
            }
        }
Example #20
0
 public static void server_OnPlayerJoin(this RoomServer roomServer, DuelServer server, string name, string room)
 {
     if (string.IsNullOrEmpty(name)) return;
     lock (roomServer.Clients)
     {
         Session player = null;
         if (roomServer.Clients.TryGetValue(name, out player))
             player.RoomName = room;
     }
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.PlayerEnter);
         writer.Write(server.Port);
         writer.WriteUnicode(name, 20);
         writer.WriteUnicode(room, 20);
         roomServer.SendAll(writer.Content);
     }
 }
Example #21
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);
            }
        }