Exemplo n.º 1
0
        public static void ProcessLoginRequest(string username, string password, int playerNumber)
        {
            int groupID  = 0;
            int playerID = 0;

            for (int i = 0; i < Network.Players.Length; i++)
            {
                if (Network.Players[i].Username.ToLower() == username.ToLower())
                {
                    Network.SendTextToPlayer(HEROsMod.HeroText("AccountAlreadyLoggedIn"), playerNumber);
                    return;
                }
            }
            if (DatabaseController.Login(ref username, password, ref playerID, ref groupID))
            {
                Network.Players[playerNumber].Username = username;
                Network.Players[playerNumber].ID       = playerID;
                if (groupID == 0)
                {
                    groupID = Network.DefaultGroup.ID;
                    DatabaseController.SetPlayerGroup(playerID, groupID);
                }
                Network.Players[playerNumber].Group = Network.GetGroupByID(groupID);
                if (Network.Players[playerNumber].UsingHEROsMod)
                {
                    LoginSuccess(playerNumber);
                }
                Network.SendTextToPlayer(string.Format(HEROsMod.HeroText("LoggedInSuccessfully"), Network.Players[playerNumber].Group.Name), playerNumber, Color.Green);
            }
            else
            {
                Network.SendTextToPlayer(HEROsMod.HeroText("InvalidUsernameOrPassword"), playerNumber, Color.Red);
            }
        }
Exemplo n.º 2
0
        public static void ProcessLoginRequest(string username, string password, int playerNumber)
        {
            int groupID  = 0;
            int playerID = 0;

            for (int i = 0; i < Network.Players.Length; i++)
            {
                if (Network.Players[i].Username.ToLower() == username.ToLower())
                {
                    Network.SendTextToPlayer("This account is already logged on in this server.", playerNumber);
                    return;
                }
            }
            if (DatabaseController.Login(ref username, password, ref playerID, ref groupID))
            {
                Network.Players[playerNumber].Username = username;
                Network.Players[playerNumber].ID       = playerID;
                if (groupID == 0)
                {
                    groupID = Network.DefaultGroup.ID;
                    DatabaseController.SetPlayerGroup(playerID, groupID);
                }
                Network.Players[playerNumber].Group = Network.GetGroupByID(groupID);
                if (Network.Players[playerNumber].UsingHEROsMod)
                {
                    LoginSuccess(playerNumber);
                }
                Network.SendTextToPlayer("You have successfully logged in.  You are in the " + Network.Players[playerNumber].Group.Name + " Group.", playerNumber, Color.Green);
            }
            else
            {
                Network.SendTextToPlayer("Invalid Username or Password", playerNumber, Color.Red);
            }
        }
Exemplo n.º 3
0
        private static void ProcessSetPlayerGroupRequest(ref BinaryReader reader, int playerNumber)
        {
            if (Network.Players[playerNumber].Group.IsAdmin)
            {
                int playerIndex = reader.ReadInt32();
                int groupID     = reader.ReadInt32();

                Network.Players[playerIndex].Group = Network.GetGroupByID(groupID);
                SendPlayerPermissions(playerIndex);
                DatabaseController.SetPlayerGroup(Network.Players[playerIndex].ID, groupID);
            }
        }
Exemplo n.º 4
0
        private static void ProcessSetOfflinePlayerGroupRequest(ref BinaryReader reader, int playerNumber)
        {
            if (Network.Players[playerNumber].Group.IsAdmin)
            {
                int id      = reader.ReadInt32();
                int groupID = reader.ReadInt32();

                //Network.Players[id].Group = Network.GetGroupByID(groupID);
                //SendPlayerPermissions(id);
                DatabaseController.SetPlayerGroup(id, groupID);
                for (int i = 0; i < Network.Players.Length; i++)
                {
                    HEROsModPlayer player = Network.Players[i];
                    if (player.ServerInstance.IsActive && player.Group.IsAdmin)
                    {
                        GeneralMessages.SendRegisteredUsersToPlayer(i);
                    }
                }
                //GeneralMessages.SendRegisteredUsersToPlayer(playerNumber);
            }
        }
Exemplo n.º 5
0
		// TODO -- How will any of these work....?
		public static bool CheckIncomingDataForHEROsModMessage(ref byte msgType, ref BinaryReader binaryReader, int playerNumber)
		{
			long readerPos = binaryReader.BaseStream.Position;

			switch (msgType)
			{
				case 12:
					if (NetworkMode == NetworkMode.Server)
					{
						//if (CTF.CaptureTheFlag.GameInProgress && Netplay.Clients[playerNumber].State == 10)
						//{
						//	if (Players[playerNumber].CTFTeam != CTF.TeamColor.None)
						//	{
						//		CTF.CTFMessages.SendPlayerToSpawnPlatform(Players[playerNumber]);
						//		return true;
						//	}

						//}
						if (Netplay.Clients[playerNumber].State == 3)
						{
							PlayerJoined(playerNumber);
						}
					}
					break;
				//case 14:
				//	if (NetworkMode != global::HEROsModMod.NetworkMode.Server)
				//	{
				//		if (CTF.CaptureTheFlag.GameInProgress)
				//		{
				//			int index = (int)binaryReader.ReadByte();
				//			byte active = binaryReader.ReadByte();
				//			if (Players[index].CTFTeam == CTF.TeamColor.None && active == 1 && Players[index].GameInstance.ghost)
				//			{
				//				return true;
				//			}
				//		}
				//	}
				//	break;
				case 17: //Terrain Modified
					if (NetworkMode == NetworkMode.Server)
					{
						bool canBuild = false;
						TileModifyType tileModifyType = (TileModifyType)binaryReader.ReadByte();
						int x = (int)binaryReader.ReadInt16();
						int y = (int)binaryReader.ReadInt16();
						short placeType = binaryReader.ReadInt16();
						int style = (int)binaryReader.ReadByte();
						bool fail = placeType == 1;
						HEROsModPlayer player = Players[playerNumber];

						Tile tile;
						if (x >= 0 && y >= 0 && x < Main.maxTilesX && y < Main.maxTilesY)
						{
							tile = Main.tile[x, y];
						}
						else
						{
							binaryReader.BaseStream.Position = readerPos;
							return false;
						}

						//if (CTF.CaptureTheFlag.GameInProgress && player.CTFTeam != CTF.TeamColor.None && CTF.CaptureTheFlag.AllowTerrainModification)
						//{
						//	canBuild = true;
						//	if (CTF.CaptureTheFlag.ListeningForTileChanges)
						//	{
						//		Tile backupTile = CTF.CaptureTheFlag.ModifiedTiles[x, y];
						//		if (backupTile == null)
						//		{
						//			CTF.CaptureTheFlag.ModifiedTiles[x, y] = new Tile();
						//			CTF.CaptureTheFlag.ModifiedTiles[x, y].CopyFrom(tile);
						//			Console.WriteLine("tile added");
						//		}
						//	}
						//}
						if (!canBuild)
						{
							canBuild = PlayerHasPermissionToBuildAtBlock(player, x, y);
						}

						if (tileModifyType == TileModifyType.PlaceTile && placeType == TileID.LandMine)
						{
							SendTextToPlayer("Landmines are disabled on this server", playerNumber, Color.Red);
						}
						else if (canBuild)
						{
							TileLastChangedBy[x, y] = player.ID;
							binaryReader.BaseStream.Position = readerPos;
							if (tileModifyType == TileModifyType.KillTile)
							{
								LastTileKilledBy = player;
								WorldGen.KillTile(x, y, fail, false, false);
								NetMessage.SendData(17, -1, playerNumber, "", (int)tileModifyType, (float)x, (float)y, (float)placeType, style);
								LastTileKilledBy = null;
								return true;
							}
							else
							{
								TileChangeController.RecordChanges(player, x, y);
							}
							return false;
						}
						else
						{
							SendTextToPlayer("You do not have permission to build here", playerNumber, Color.Red);
						}

						switch (tileModifyType)
						{
							case TileModifyType.KillTile:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PlaceTile, (float)x, (float)y, (float)tile.type, tile.slope());
								break;
							case TileModifyType.PlaceTile:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.KillTile, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.KillWall:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PlaceWall, (float)x, (float)y, (float)tile.wall, style);
								break;
							case TileModifyType.PlaceWall:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.KillWall, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.KillTileNoItem:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PlaceTile, (float)x, (float)y, (float)tile.type, tile.slope());
								break;
							case TileModifyType.PlaceWire:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.KillWire, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.PlaceWire2:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.KillWire2, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.PlaceWire3:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.KillWire3, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.KillWire:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PlaceWire, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.KillWire2:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PlaceWire2, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.KillWire3:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PlaceWire3, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.KillActuator:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PlaceActuator, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.PlaceActuator:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.KillActuator, (float)x, (float)y, (float)placeType, style);
								break;
							case TileModifyType.PoundTile:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.PoundTile, (float)x, (float)y, (float)placeType, tile.slope());
								break;
							case TileModifyType.SlopeTile:
								NetMessage.SendData(17, playerNumber, -1, "", (int)TileModifyType.SlopeTile, (float)x, (float)y, (float)placeType, tile.slope());
								break;
						}
						return true;
					}
					break;
				case 25: //revieved a chat message

					binaryReader.ReadByte();
					Color color = binaryReader.ReadRGB();
					string text = binaryReader.ReadString();
					if (NetworkMode == NetworkMode.Client)
					{
						if (text == HEROsModCheckMessage)
						{
							ServerUsingHEROsMod = true;
							HEROsMod.ServiceHotbar.Visible = true;
							GeneralMessages.TellSereverImUsingHEROsMod();
							return true;
						}
					}
					else if (NetworkMode == NetworkMode.Server)
					{
						if (text.Length > 1 && text.Substring(0, 1) == "/")
						{
							string[] parameters = text.Substring(1, text.Length - 1).Split(' ');
							parameters[0] = parameters[0].ToLower();
							switch (parameters[0])
							{
								case "auth":
									if (parameters.Length != 2 || parameters[1].Length != 6)
									{
										SendTextToPlayer("Invalid Input", playerNumber);
										return true;
									}
									string authStr = parameters[1];
									if (authStr == AuthCode.ToString())
									{
										if (!Players[playerNumber].UsingHEROsMod)
										{
											SendTextToPlayer("You need HEROsMod Mod to use this feature", playerNumber);
											return true;
										}
										if (Players[playerNumber].Username.Length > 0)
										{
											Players[playerNumber].Group = AdminGroup;
											DatabaseController.SetPlayerGroup(Players[playerNumber].ID, Players[playerNumber].Group.ID);
											LoginService.SendPlayerPermissions(playerNumber);
											SendTextToPlayer("You are now Admin", playerNumber);
											return true;
										}
										else
										{
											SendTextToPlayer("Please login first", playerNumber);
											return true;
										}
									}
									else
									{
										SendTextToPlayer("Invalid Auth Code", playerNumber);
										return true;
									}
								case "login":
									if (parameters.Length != 3)
									{
										SendTextToPlayer("Invalid Input", playerNumber);
										return true;
									}
									LoginService.ProcessLoginRequest(parameters[1], parameters[2], playerNumber);
									return true;
								case "logout":
									if (parameters.Length != 1)
									{
										SendTextToPlayer("Invalid Input", playerNumber);
										return true;
									}
									LoginService.ProcessLogoutRequest(playerNumber);
									return true;
								case "register":
									if (parameters.Length != 3)
									{
										SendTextToPlayer("Invalid Input", playerNumber);
										return true;
									}
									LoginService.ProcessRegistrationRequest(parameters[1], parameters[2], playerNumber);
									break;
								case "help":
									if (parameters.Length != 1)
									{
										SendTextToPlayer("Invalid Input", playerNumber);
									}
									SendTextToPlayer("/login <username> <password> - Login with your account", playerNumber);
									SendTextToPlayer("/register <username> <password> - Create an account", playerNumber);
									SendTextToPlayer("/logout - Logout of your account", playerNumber);
									SendTextToPlayer("Use HEROsMod Mod to unlock all server features.", playerNumber);
									break;
								default:
									SendTextToPlayer("Invalid Command, type /help for a list of commands.", playerNumber);
									break;

							}
						}
						else
						{
							string text2 = text.ToLower();
							if (text2 == Lang.mp[6] || text2 == Lang.mp[21])
							{
								string text3 = "";
								for (int i = 0; i < 255; i++)
								{
									if (Main.player[i].active)
									{
										if (text3 == "")
										{
											text3 = Main.player[i].name;
										}
										else
										{
											text3 = text3 + ", " + Main.player[i].name;
										}
									}
								}
								NetMessage.SendData(25, playerNumber, -1, Lang.mp[7] + " " + text3 + ".", 255, 255f, 240f, 20f, 0);
							}
							else if (text2.StartsWith("/me "))
							{
								NetMessage.SendData(25, -1, -1, "*" + Main.player[playerNumber].name + " " + text.Substring(4), 255, 200f, 100f, 0f, 0);
							}
							else if (text2 == Lang.mp[8])
							{
								NetMessage.SendData(25, -1, -1, string.Concat(new object[]
							{
								"*",
								Main.player[playerNumber].name,
								" ",
								Lang.mp[9],
								" ",
								Main.rand.Next(1, 101)
							}), 255, 255f, 240f, 20f, 0);
							}
							else if (text2.StartsWith("/p "))
							{
								int num28 = Main.player[playerNumber].team;
								color = Main.teamColor[num28];
								if (num28 != 0)
								{
									for (int i = 0; i < 255; i++)
									{
										if (Main.player[i].team == num28)
										{
											NetMessage.SendData(25, i, -1, text.Substring(3), 255, (float)color.R, (float)color.G, (float)color.B, 0);
										}
									}
								}
								else
								{
									NetMessage.SendData(25, playerNumber, -1, Lang.mp[10], 255, 255f, 240f, 20f, 0);
								}
							}
							else
							{
								return false;
								// why are chat messages randomized?
								/*color = chatColor[chatColorIndex];
								chatColorIndex++;
								if (chatColorIndex >= chatColor.Length) chatColorIndex = 0;
								NetMessage.SendData(25, -1, -1, text, 255, (float)color.R, (float)color.G, (float)color.B, 0);
								if (Main.dedServ)
								{
									Console.WriteLine("<" + Main.player[playerNumber].name + "> " + text);
								}*/
							}
						}
						return true;
					}
					break;
				//case 27:
				//	if (ItemBanner.ItemsBanned && !Players[playerNumber].Group.IsAdmin)
				//	{
				//		int projIdentity = (int)binaryReader.ReadInt16();
				//		Vector2 position = binaryReader.ReadVector2();
				//		Vector2 velocity = binaryReader.ReadVector2();
				//		float knockback = binaryReader.ReadSingle();
				//		int damage = (int)binaryReader.ReadInt16();
				//		int owner = (int)binaryReader.ReadByte();
				//		int type = (int)binaryReader.ReadInt16();

				//		Console.WriteLine("Prof: " + type);
				//		int[] bannedProjectiles = ItemBanner.bannedProjectiles;
				//		for (int i = 0; i < bannedProjectiles.Length; i++)
				//		{
				//			if (bannedProjectiles[i] == type)
				//			{
				//				Projectile newProj = new Projectile();
				//				newProj.SetDefaults(type);
				//				SendTextToPlayer(newProj.name + " is banned on the server", playerNumber, Color.Red);

				//				int projIndex = 0;
				//				for (int j = 0; j < 1000; j++)
				//				{
				//					if (!Main.projectile[j].active)
				//					{
				//						Projectile proj = Main.projectile[j];
				//						proj.owner = owner;
				//						projIndex = j;
				//						break;
				//					}
				//				}

				//				NetMessage.SendData(27, playerNumber, -1, "", projIndex);
				//				NetMessage.SendData(29, playerNumber, -1, "", projIdentity, (float)owner);
				//				return true;
				//			}
				//		}
				//	}
				//	break;
				//case 30:
				//	if (NetworkMode == global::HEROsModMod.NetworkMode.Server)
				//	{
				//		if (CTF.CaptureTheFlag.GameInProgress)
				//		{
				//			SendTextToPlayer("You cannot change your hostility while Capture the Flag is in progress.", playerNumber);
				//			CTF.CaptureTheFlag.SetPlayerHostility(Players[playerNumber]);
				//			return true;
				//		}
				//	}
				//	break;
				//case 45:
				//	if (NetworkMode == global::HEROsModMod.NetworkMode.Server)
				//	{
				//		if (CTF.CaptureTheFlag.GameInProgress)
				//		{
				//			SendTextToPlayer("You cannot change parties while Capture the Flag is in progress.", playerNumber);
				//			CTF.CaptureTheFlag.SetPlayerHostility(Players[playerNumber]);
				//			return true;
				//		}
				//	}
				//	break;
				case 63: //block painted
					if (NetworkMode == global::HEROsMod.NetworkMode.Server)
					{
						int x = (int)binaryReader.ReadInt16();
						int y = (int)binaryReader.ReadInt16();
						byte paintColor = binaryReader.ReadByte();
						HEROsModPlayer player = Players[playerNumber];

						if (PlayerHasPermissionToBuildAtBlock(player, x, y))
						{
							TileLastChangedBy[x, y] = player.ID;
							binaryReader.BaseStream.Position = readerPos;
							return false;
						}
						else
						{
							NetMessage.SendData(63, playerNumber, -1, "", x, (float)y, (float)Main.tile[x, y].color());
							SendTextToPlayer("You do not have permission to build here", playerNumber, Color.Red);
							return true;
						}
					}
					break;
				case 64: //wall painted
					if (NetworkMode == global::HEROsMod.NetworkMode.Server)
					{
						int x = (int)binaryReader.ReadInt16();
						int y = (int)binaryReader.ReadInt16();
						byte paintColor = binaryReader.ReadByte();
						HEROsModPlayer player = Players[playerNumber];

						if (PlayerHasPermissionToBuildAtBlock(player, x, y))
						{
							TileLastChangedBy[x, y] = player.ID;
							binaryReader.BaseStream.Position = readerPos;
							return false;
						}
						else
						{
							NetMessage.SendData(64, playerNumber, -1, "", x, (float)y, (float)Main.tile[x, y].wallColor());
							SendTextToPlayer("You do not have permission to build here", playerNumber, Color.Red);
							return true;
						}
					}
					break;
			}

			//if (msgType == HEROsModNetworkMessageType)
			//{
			//    //We found a HEROsMod only message
			//    MessageType subMsgType = (MessageType)binaryReader.ReadByte();
			//    switch(subMsgType)
			//    {
			//        case MessageType.GeneralMessage:
			//            GeneralMessages.ProcessData(ref binaryReader, playerNumber);
			//            break;
			//        case MessageType.LoginMessage:
			//            LoginService.ProcessData(ref binaryReader, playerNumber);
			//            break;
			//        case MessageType.CTFMessage:
			//            CTF.CTFMessages.ProcessData(ref binaryReader, playerNumber);
			//            break;
			//    }
			//}

			//we need to set the stream position back to where it was before we got it
			binaryReader.BaseStream.Position = readerPos;
			return false;
		}