Exemple #1
0
        public void LobbyError(string message)
        {
            GameServerPacket join = new GameServerPacket(StocMessage.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);
            Send(join);

            GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);

            enter.WriteUnicode("[err]" + message, 20);
            enter.Write((byte)0);
            Send(enter);
        }
Exemple #2
0
        public void ServerMessage(string msg, PlayerType type = PlayerType.Yellow, string head = "[Server] ")
        {
            string           finalmsg = head + msg;
            GameServerPacket packet   = new GameServerPacket(StocMessage.Chat);

            packet.Write((short)type);
            packet.WriteUnicode(finalmsg, finalmsg.Length + 1);
            Send(packet);
        }
Exemple #3
0
		public static void ServerMessage(this GameSession client, string msg, PlayerType type=PlayerType.Yellow,bool isNow=true)
		{
			string finalmsg = "[Server] " + msg;
			using(GameServerPacket packet = new GameServerPacket(StocMessage.Chat)){
				packet.Write((short)type);
				packet.WriteUnicode(finalmsg, finalmsg.Length + 1);
				client.Send(packet, isNow);
			}
		}
Exemple #4
0
		public void ServerMessage(string msg, PlayerType type=PlayerType.Yellow, string head="[Server] ")
		{
			string finalmsg = head + msg;
			GameServerPacket packet = new GameServerPacket(StocMessage.Chat);
			packet.Write((short)type);
			packet.WriteUnicode(finalmsg, finalmsg.Length + 1);
			Send(packet);
		}
Exemple #5
0
		public void LobbyError(string message)
		{
			GameServerPacket join = new GameServerPacket(StocMessage.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);
			Send(join);

			GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
			enter.WriteUnicode("[err]" + message, 20);
			enter.Write((byte)0);
			Send(enter);
		}
Exemple #6
0
 public void ServerMessage(string msg, PlayerType color = PlayerType.Yellow, bool isNow = true)
 {
     string finalmsg = "[Server] " + msg;
     using (GameServerPacket packet = new GameServerPacket(StocMessage.Chat))
     {
         packet.Write((short)color);
         packet.WriteUnicode(finalmsg, finalmsg.Length + 1);
         SendToAll(packet, isNow);
     }
 }
Exemple #7
0
 private void SendDuelingPlayers(GameSession player, bool isNow = true)
 {
     for (int i = 0; i < Players.Length; i++)
     {
         using (GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter))
         {
             int id = i;
             if (m_swapped)
             {
                 if (IsTag)
                 {
                     if (i == 0 || id == 1)
                         id = i + 2;
                     else
                         id = i - 2;
                 }
                 else
                     id = 1 - i;
             }
             enter.WriteUnicode(Players[id] == null ? "???" : Players[id].Name, 20);
             enter.Write((byte)i);
             player.Send(enter, isNow);
         }
     }
 }
Exemple #8
0
		public void Connect(ServerInfo info, User user){
			if(client!=null){
				client.Close();
			}
			client = new AsyncClient();
			try{
				client.Connect(info.Host, info.Port);
				using(GameServerPacket login = new GameServerPacket()){
					login.WriteUnicode(user.Name, 20);
					login.WriteUnicode(user.Password, 32);
					login.Use();
					client.BeginSend(login.Content);
				}
			}catch(Exception){
				
			}
		}
Exemple #9
0
        public void MoveToDuelist(GameSession player)
        {
            if (State != GameState.Lobby)
                return;
            int pos = GetAvailablePlayerPos();
            if (pos == -1)
                return;
            if (player.Type != (int)PlayerType.Observer)
            {
                if (!IsTag || IsReady[player.Type])
                    return;

                pos = (player.Type + 1) % 4;
                while (Players[pos] != null)
                    pos = (pos + 1) % 4;

                using (GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange))
                {
                    change.Write((byte)((player.Type << 4) + pos));
                    SendToAll(change);
                }
                Players[player.Type] = null;
                Players[pos] = player;
                player.Type = pos;
                player.SendTypeChange();
            }
            else
            {
                lock (Observers)
                    Observers.Remove(player);
                Players[pos] = player;
                player.Type = pos;

                using (GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter))
                {
                    enter.WriteUnicode(player.Name, 20);
                    enter.Write((byte)pos);
                    SendToAll(enter);
                }

                using (GameServerPacket nwatch = new GameServerPacket(StocMessage.HsWatchChange))
                {
                    nwatch.Write((short)Observers.Count);
                    SendToAll(nwatch);
                }

                player.SendTypeChange();
            }
        }
Exemple #10
0
		public void ServerMessage(string msg)
		{
			string finalmsg = "[Server] " + msg;
			GameServerPacket packet = new GameServerPacket(StocMessage.Chat);
			packet.Write((short)PlayerType.Yellow);
			packet.WriteUnicode(finalmsg, finalmsg.Length + 1);
			SendToAll(packet);
		}
Exemple #11
0
		public void Chat(Player player, string msg)
		{
			GameServerPacket packet = new GameServerPacket(StocMessage.Chat);
			packet.Write((short)player.Type);
			packet.WriteUnicode(msg, msg.Length + 1);
			SendToAllBut(packet, player);
		}
Exemple #12
0
		public void AddPlayer(Player player)
		{
			if (State != GameState.Lobby)
			{
				if (State == GameState.End)
					return;
				//断线重连
//				if(CanPause && IsPause){
//					for(int i=0;i<PlayerNames.Length;i++){
//						if(PlayerNames[i] == player.Name){
//							if(Players[i] == null){
//								//重新加入游戏
//								player.Type = i;
//								Players[i] = player;
//								AutoEndTrun = Program.Config.AutoEndTurn;
//								GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
//								enter.Write(player.Name, 20);
//								enter.Write((byte)i);
//								SendToAll(enter);
//								SendJoinGame(player);
//								player.SendTypeChange();
//								//player.Send(new GameServerPacket(StocMessage.DuelStart));
//								InitNewSpectator(player, i);
//								IsPause = false;
//								return;
//							}
//							break;
//						}
//					}
//				}
				player.Type = (int)PlayerType.Observer;
				SendJoinGame(player);
				player.SendTypeChange();
				player.Send(new GameServerPacket(StocMessage.DuelStart));
				Observers.Add(player);
				if (State == GameState.Duel){
					//中途观战
					InitNewSpectator(player);
				}else if(State == GameState.Side){
					player.ServerMessage(Messages.MSG_WATCH_SIDE);
				}
				return;
			}

			if (HostPlayer == null)
				HostPlayer = player;

			int pos = GetAvailablePlayerPos();
			if (pos != -1)
			{
				GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
				enter.WriteUnicode(player.Name, 20);
				enter.Write((byte)pos);
				SendToAll(enter);
				PlayerNames[pos] = player.Name;
				Players[pos] = player;
				IsReady[pos] = false;
				player.Type = pos;
			}
			else
			{
				GameServerPacket watch = new GameServerPacket(StocMessage.HsWatchChange);
				watch.Write((short)(Observers.Count + 1));
				SendToAll(watch);

				player.Type = (int)PlayerType.Observer;
				Observers.Add(player);
				if(player.IsAuthentified){
					SendToAll(GameManager.getMessage("[Server] "+player.Name+" watch game.", PlayerType.White));
				}
			}

			SendJoinGame(player);
			player.SendTypeChange();

			for (int i = 0; i < Players.Length; i++)
			{
				if (Players[i] != null)
				{
					GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
					enter.WriteUnicode(Players[i].Name, 20);
					enter.Write((byte)i);
					player.Send(enter);
					if (IsReady[i])
					{
						GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange);
						change.Write((byte)((i << 4) + (int)PlayerChange.Ready));
						player.Send(change);
					}
				}
			}

			if (Observers.Count > 0)
			{
				GameServerPacket nwatch = new GameServerPacket(StocMessage.HsWatchChange);
				nwatch.Write((short)Observers.Count);
				player.Send(nwatch);
			}
		}
Exemple #13
0
		private void HandleError(string error)
		{
			const string log = "LuaErrors.log";
			if (File.Exists(log))
			{
				foreach (string line in File.ReadAllLines(log))
				{
					if (line == error)
						return;
				}
			}

			StreamWriter writer = new StreamWriter(log, true);
			writer.WriteLine(error);
			writer.Close();

			GameServerPacket packet = new GameServerPacket(StocMessage.Chat);
			packet.Write((short)PlayerType.Observer);
			packet.WriteUnicode(error, error.Length + 1);
			SendToAll(packet);
		}
Exemple #14
0
		private void SendDuelingPlayers(Player player)
		{
			for (int i = 0; i < Players.Length; i++)
			{

				GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter);
				int id = i;
				if (m_swapped)
				{
					if (IsTag)
					{
						if (i == 0 || id == 1)
							id = i + 2;
						else
							id = i - 2;
					}
					else
						id = 1 - i;
				}
				enter.WriteUnicode(PlayerNames[id], 20);
				enter.Write((byte)i);
				player.Send(enter);
			}
		}
Exemple #15
0
		public static void OnChat(GameSession client, GameClientPacket packet){
			if (!client.IsAuthentified){
				return;
			}
			string msg = packet.ReadUnicode(256);
			if(client.Game==null){
				return;
			}
			if(!client.OnChatCommand(msg)){
				using(GameServerPacket chat = new GameServerPacket(StocMessage.Chat)){
					chat.Write((short)client.Type);
					chat.WriteUnicode(msg, msg.Length + 1);
					client.Game.SendToAllBut(chat, client);
				}
			}
		}
Exemple #16
0
		public static void LobbyError(this GameSession client, string message,bool isNow=true)
		{
			using(GameServerPacket join = new GameServerPacket(StocMessage.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);
				client.Send(join, false);
			}
			
			using(GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter)){
				enter.WriteUnicode("[err]" + message, 20);
				enter.Write((byte)0);
				client.Send(enter, isNow);
			}
		}
Exemple #17
0
        public void AddPlayer(GameSession player)
        {
            //			if(IsJoin(player)){
            ////				/玩家已经在游戏
            //				player.LobbyError(Messages.MSG_PLAYER_INGAME);
            //				return;
            //			}
            Logger.Debug("add " + player.Name + " to " + Name);
            if (State != GameState.Lobby)
            {
                if (State == GameState.End)
                    return;
                player.Type = (int)PlayerType.Observer;
                SendJoinGame(player);
                player.SendTypeChange();
                player.Send(GameServerPacket.EmtryMessage(StocMessage.DuelStart));
                lock (Observers)
                    Observers.Add(player);
                if (State == GameState.Duel)
                {
                    //中途观战
                    InitNewSpectator(player);
                }
                else if (State == GameState.Side)
                {
                    player.ServerMessage(Messages.MSG_WATCH_SIDE);
                }
                ServerApi.OnPlayerEnter(player, this);
                return;
            }
            if (HostPlayer == null)
                HostPlayer = player;
            int pos = GetAvailablePlayerPos();
            if (pos != -1)
            {
                Players[pos] = player;
                IsReady[pos] = false;

                player.Type = pos;
                using (GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter))
                {
                    enter.WriteUnicode(player.Name, 20);
                    enter.Write((byte)pos);
                    SendToAll(enter);
                }
                //	Server.OnPlayEvent(PlayerStatu.PlayerReady, player);
            }
            else
            {
                using (GameServerPacket watch = new GameServerPacket(StocMessage.HsWatchChange))
                {
                    watch.Write((short)(Observers.Count + 1));
                    SendToAll(watch);
                }
                player.Type = (int)PlayerType.Observer;
                lock (Observers)
                    Observers.Add(player);
                //				if(player.IsAuthentified){
                //					ServerMessage("[Server] "+player.Name+" watch game.", PlayerType.White);
                //				}
            }
            SendJoinGame(player);
            player.SendTypeChange();

            for (int i = 0; i < Players.Length; i++)
            {
                if (Players[i] != null)
                {
                    using (GameServerPacket enter = new GameServerPacket(StocMessage.HsPlayerEnter))
                    {
                        enter.WriteUnicode(Players[i].Name, 20);
                        enter.Write((byte)i);
                        player.Send(enter, false);
                    }
                    if (IsReady[i])
                    {
                        using (GameServerPacket change = new GameServerPacket(StocMessage.HsPlayerChange))
                        {
                            change.Write((byte)((i << 4) + (int)PlayerChange.Ready));
                            player.Send(change, false);
                        }
                    }
                }
            }
            bool _watch = false;
            lock (Observers)
            {
                _watch = Observers.Count > 0;
            }
            if (_watch)
            {
                using (GameServerPacket nwatch = new GameServerPacket(StocMessage.HsWatchChange))
                {
                    nwatch.Write((short)Observers.Count);
                    player.Send(nwatch, false);
                }
            }
            player.PeekSend();
            ServerApi.OnPlayerEnter(player, this);
        }
Exemple #18
0
		public static GameServerPacket getMessage(string finalmsg,PlayerType type=PlayerType.Yellow){
			GameServerPacket packet = new GameServerPacket(StocMessage.Chat);
			packet.Write((short)type);
			packet.WriteUnicode(finalmsg, finalmsg.Length + 1);
			return packet;
		}
Exemple #19
0
 private void HandleError(string error)
 {
     using (GameServerPacket packet = new GameServerPacket(StocMessage.Chat))
     {
         packet.Write((short)PlayerType.Observer);
         packet.WriteUnicode(error, error.Length + 1);
         SendToAll(packet);
     }
     Logger.Error("Lua Error:" + error);
 }