Exemplo n.º 1
0
		public static bool onChat(GameConfig config,Player player,string msg)
		{
			if(!string.IsNullOrEmpty(msg)){
				msg = msg.Trim();
				if(msg=="/ai"){
					if(Program.Config.MaxAICount==0){
						player.ServerMessage(Messages.MSG_NO_AI);
					}
					else if(config!=null && AddAI(config.Name)){
						player.ServerMessage(Messages.MSG_ADD_AI);
					}else{
						player.ServerMessage(Messages.MSG_NO_FREE_AI);
					}
					return false;
				}
//				if(msg.StartsWith("@") && !Program.Config.PrivateChat){
//					player.ServerMessage(Messages.MSG_BAN_PCHAT);
//					return false;
//				}
//				if(msg.StartsWith("@server ")){
//					Logger.WriteLineWithColor(player.Name+":"+msg.Replace("@server ",""), ConsoleColor.Yellow);
//					return false;
//				}else if(msg.StartsWith("@system ")){
//					Logger.WriteLineWithColor(player.Name+":"+msg.Replace("@system ",""), ConsoleColor.Yellow);
//					return false;
//				}else if(msg.StartsWith("@@ ")){
//					Logger.WriteLineWithColor(player.Name+":"+msg.Replace("@@ ",""), ConsoleColor.Yellow);
//					return false;
//				}else if(msg.StartsWith("@")){
//					//私聊
//					int i=msg.IndexOf(' ');
//					if(i>0){
//						try{
//							string name=msg.Substring(1, i-1);
//							string cxt=msg.Substring(i+1);
//							if(GameManager.SendErrorMessage(player.Name+": "+cxt, name).Count==0){
//								player.ServerMessage(Messages.MSG_SEND_FAIL);
//							}else{
//								return false;
//							}
//						}catch(Exception){
//
//						}
//					}
//				}
			}
			return true;
		}
Exemplo n.º 2
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);
			}
		}