mirror of
https://github.com/islehorse/HISP.git
synced 2025-04-21 20:25:51 +12:00
Add Dress up Multiroom?
This commit is contained in:
parent
13435cf37f
commit
99c604e926
14 changed files with 420 additions and 47 deletions
|
@ -8,6 +8,7 @@ using HISP.Game.Inventory;
|
|||
using HISP.Game.Items;
|
||||
using HISP.Security;
|
||||
using HISP.Game.Services;
|
||||
using HISP.Game.SwfModules;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
|
@ -42,6 +43,7 @@ namespace HISP.Server
|
|||
string PoetryRooms = "CREATE TABLE IF NOT EXISTS PoetryRooms(poetId INT, X INT, Y INT, roomId INT)";
|
||||
string SavedDrawings = "CREATE TABLE IF NOT EXISTS SavedDrawings(playerId INT, Drawing1 TEXT(65535), Drawing2 TEXT(65535), Drawing3 TEXT(65535))";
|
||||
string DrawingRooms = "CREATE TABLE IF NOT EXISTS DrawingRooms(roomId INT, Drawing TEXT(65535))";
|
||||
string DressupRooms = "CREATE TABLE IF NOT EXISTS DressupRooms(roomId INT, peiceId INT, active TEXT(3), x INT, y INT)";
|
||||
string Horses = "CREATE TABLE IF NOT EXISTS Horses(randomId INT, ownerId INT, leaseTime INT, leaser INT, breed INT, name TEXT(128), description TEXT(1028), sex TEXT(128), color TEXT(128), health INT, shoes INT, hunger INT, thirst INT, mood INT, groom INT, tiredness INT, experience INT, speed INT, strength INT, conformation INT, agility INT, endurance INT, inteligence INT, personality INT, height INT, saddle INT, saddlepad INT, bridle INT, companion INT, autoSell INT, trainTimer INT, category TEXT(128), spoiled INT, magicUsed INT, hidden TEXT(3))";
|
||||
string WildHorse = "CREATE TABLE IF NOT EXISTS WildHorse(randomId INT, originalOwner INT, breed INT, x INT, y INT, name TEXT(128), description TEXT(1028), sex TEXT(128), color TEXT(128), health INT, shoes INT, hunger INT, thirst INT, mood INT, groom INT, tiredness INT, experience INT, speed INT, strength INT, conformation INT, agility INT, endurance INT, inteligence INT, personality INT, height INT, saddle INT, saddlepad INT, bridle INT, companion INT, timeout INT, autoSell INT, trainTimer INT, category TEXT(128), spoiled INT, magicUsed INT)";
|
||||
string LastPlayer = "CREATE TABLE IF NOT EXISTS LastPlayer(roomId TEXT(1028), playerId INT)";
|
||||
|
@ -67,6 +69,19 @@ namespace HISP.Server
|
|||
Logger.WarnPrint(e.Message);
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = DressupRooms;
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WarnPrint(e.Message);
|
||||
};
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
|
@ -509,6 +524,98 @@ namespace HISP.Server
|
|||
return count >= 1;
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateDressupRoomPeice(int roomId, int peiceId, bool active, int x, int y)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "INSERT INTO DressupRooms VALUES(@roomId, @peiceId, @active, @x, @y)";
|
||||
sqlCommand.Parameters.AddWithValue("@roomId", roomId);
|
||||
sqlCommand.Parameters.AddWithValue("@peiceId", peiceId);
|
||||
sqlCommand.Parameters.AddWithValue("@active", active ? "YES" : "NO");
|
||||
sqlCommand.Parameters.AddWithValue("@x", x);
|
||||
sqlCommand.Parameters.AddWithValue("@y", y);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDressupRoomPeiceX(int roomId, int peiceId, int newX)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "UPDATE DressupRooms SET x=@x WHERE roomId=@roomId AND peiceId=@peiceId";
|
||||
sqlCommand.Parameters.AddWithValue("@roomId", roomId);
|
||||
sqlCommand.Parameters.AddWithValue("@peiceId", peiceId);
|
||||
sqlCommand.Parameters.AddWithValue("@x", newX);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDressupRoomPeiceY(int roomId, int peiceId, int newY)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "UPDATE DressupRooms SET y=@y WHERE roomId=@roomId AND peiceId=@peiceId";
|
||||
sqlCommand.Parameters.AddWithValue("@roomId", roomId);
|
||||
sqlCommand.Parameters.AddWithValue("@peiceId", peiceId);
|
||||
sqlCommand.Parameters.AddWithValue("@y", newY);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDressupRoomPeiceActive(int roomId, int peiceId, bool active)
|
||||
{
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "UPDATE DressupRooms SET active=@active WHERE roomId=@roomId AND peiceId=@peiceId";
|
||||
sqlCommand.Parameters.AddWithValue("@roomId", roomId);
|
||||
sqlCommand.Parameters.AddWithValue("@peiceId", peiceId);
|
||||
sqlCommand.Parameters.AddWithValue("@active", active ? "YES" : "NO");
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public static Dressup.DressupPeice[] LoadDressupRoom(Dressup.DressupRoom room)
|
||||
{
|
||||
List<Dressup.DressupPeice> peices = new List<Dressup.DressupPeice>();
|
||||
using (MySqlConnection db = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
db.Open();
|
||||
MySqlCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT * FROM DressupRooms WHERE roomId=@roomId";
|
||||
sqlCommand.Parameters.AddWithValue("@roomId", room.RoomId);
|
||||
sqlCommand.Prepare();
|
||||
MySqlDataReader reader = sqlCommand.ExecuteReader();
|
||||
while(reader.Read())
|
||||
{
|
||||
int peiceId = reader.GetInt32(1);
|
||||
bool active = reader.GetString(2) == "YES";
|
||||
int x = reader.GetInt32(3);
|
||||
int y = reader.GetInt32(4);
|
||||
Dressup.DressupPeice peice = new Dressup.DressupPeice(room, peiceId, x, y, active, false);
|
||||
peices.Add(peice);
|
||||
}
|
||||
sqlCommand.Dispose();
|
||||
}
|
||||
return peices.ToArray();
|
||||
}
|
||||
|
||||
public static int[] GetSolvedRealTimeRiddles(int playerId)
|
||||
{
|
||||
List<int> solvedRiddleId = new List<int>();
|
||||
|
|
|
@ -3325,7 +3325,10 @@ namespace HISP.Server
|
|||
{
|
||||
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to load an invalid drawing room: " + roomId);
|
||||
break;
|
||||
|
||||
}
|
||||
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true, sender.LoggedinUser);
|
||||
|
||||
if(room.Drawing != "")
|
||||
{
|
||||
byte[] drawingPacket = PacketBuilder.CreateDrawingUpdatePacket(room.Drawing);
|
||||
|
@ -3526,7 +3529,7 @@ namespace HISP.Server
|
|||
|
||||
int roomId = packet[3] - 40;
|
||||
Brickpoet.PoetryPeice[] room;
|
||||
try
|
||||
try // Make sure the room exists-
|
||||
{
|
||||
room = Brickpoet.GetPoetryRoom(roomId);
|
||||
}
|
||||
|
@ -3535,9 +3538,11 @@ namespace HISP.Server
|
|||
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to load an invalid brickpoet room: " + roomId);
|
||||
break;
|
||||
}
|
||||
|
||||
// Send list of peices
|
||||
byte[] poetPacket = PacketBuilder.CreateBrickPoetListPacket(room);
|
||||
sender.SendPacket(poetPacket);
|
||||
|
||||
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true, sender.LoggedinUser);
|
||||
}
|
||||
else if(packet[3] == PacketBuilder.BRICKPOET_MOVE)
|
||||
{
|
||||
|
@ -3566,7 +3571,7 @@ namespace HISP.Server
|
|||
Brickpoet.PoetryPeice[] room;
|
||||
Brickpoet.PoetryPeice peice;
|
||||
|
||||
try
|
||||
try // Make sure these are acturally numbers!
|
||||
{
|
||||
peiceId = int.Parse(args[1]);
|
||||
x = int.Parse(args[2]);
|
||||
|
@ -3582,11 +3587,11 @@ namespace HISP.Server
|
|||
Logger.ErrorPrint(sender.LoggedinUser.Username + " tried to move a peice in an invalid brickpoet room: " + roomId);
|
||||
break;
|
||||
}
|
||||
|
||||
// Change location in Database
|
||||
peice.X = x;
|
||||
peice.Y = y;
|
||||
|
||||
foreach(User user in GetUsersOnSpecialTileCode("MULTIROOM-" + "P" + roomId.ToString()))
|
||||
foreach(User user in GetUsersOnSpecialTileCode("MULTIROOM-" + "P" + roomId.ToString())) // Send to each user!
|
||||
{
|
||||
if (user.Id == sender.LoggedinUser.Id)
|
||||
continue;
|
||||
|
@ -3610,6 +3615,93 @@ namespace HISP.Server
|
|||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
case PacketBuilder.SWFMODULE_DRESSUPROOM:
|
||||
if (packet.Length < 6)
|
||||
{
|
||||
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent invalid DRESSUPROOM packet (swf communication, WRONG SIZE)");
|
||||
break;
|
||||
}
|
||||
if (packet[2] == PacketBuilder.DRESSUPROOM_LIST_ALL)
|
||||
{
|
||||
int roomId = packet[3] - 40;
|
||||
Dressup.DressupRoom room = Dressup.GetDressupRoom(roomId);
|
||||
|
||||
if (room.DressupPeices.Count > 0)
|
||||
{
|
||||
byte[] allDressupsResponse = PacketBuilder.CreateDressupRoomPeiceResponse(room.DressupPeices.ToArray());
|
||||
sender.SendPacket(allDressupsResponse);
|
||||
}
|
||||
|
||||
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, true, sender.LoggedinUser);
|
||||
}
|
||||
else // Move
|
||||
{
|
||||
if (packet.Length < 9)
|
||||
{
|
||||
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent invalid DRESSUPROOM MOVE packet (swf communication, WRONG SIZE)");
|
||||
break;
|
||||
}
|
||||
|
||||
int roomId = packet[2] - 40;
|
||||
if (roomId <= 0)
|
||||
{
|
||||
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent invalid DRESSUPROOM MOVE packet (swf communication, INVALID ROOM)");
|
||||
break;
|
||||
}
|
||||
Dressup.DressupRoom room = Dressup.GetDressupRoom(roomId);
|
||||
|
||||
string packetStr = Encoding.UTF8.GetString(packet);
|
||||
string moveStr = packetStr.Substring(3, packetStr.Length - 5);
|
||||
|
||||
string[] moves = moveStr.Split('|');
|
||||
|
||||
if(moves.Length < 3)
|
||||
{
|
||||
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent invalid DRESSUPROOM MOVE packet (swf communication, MOVES WRONG SIZE)");
|
||||
break;
|
||||
}
|
||||
|
||||
int peiceId;
|
||||
double moveToX;
|
||||
double moveToY;
|
||||
bool active = true;
|
||||
try // Make sure these are acturally numbers!
|
||||
{
|
||||
peiceId = int.Parse(moves[0]);
|
||||
if (moves[1] == "D" || moves[2] == "D")
|
||||
{
|
||||
active = false;
|
||||
moveToX = 0;
|
||||
moveToY = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
moveToX = double.Parse(moves[1]);
|
||||
moveToY = double.Parse(moves[2]);
|
||||
}
|
||||
}
|
||||
catch(FormatException)
|
||||
{
|
||||
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent invalid DRESSUPROOM MOVE packet (swf communication, INVALID LOCATION)");
|
||||
break;
|
||||
}
|
||||
|
||||
Dressup.DressupPeice peice = room.GetDressupPeice(peiceId);
|
||||
// Update database entries
|
||||
peice.X = Convert.ToInt32(Math.Round(moveToX));
|
||||
peice.Y = Convert.ToInt32(Math.Round(moveToY));
|
||||
peice.Active = active;
|
||||
|
||||
// Forward to other users
|
||||
byte[] movePeicePacket = PacketBuilder.CreateDressupRoomPeiceMove(peice.PeiceId, moveToX, moveToY, peice.Active);
|
||||
User[] users = GetUsersAt(sender.LoggedinUser.X, sender.LoggedinUser.Y, true, true);
|
||||
foreach(User user in users)
|
||||
{
|
||||
if (user.Id != sender.LoggedinUser.Id)
|
||||
user.LoggedinClient.SendPacket(movePeicePacket);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case PacketBuilder.SWFMODULE_ARENA:
|
||||
if (Arena.UserHasEnteredHorseInAnyArena(sender.LoggedinUser))
|
||||
|
@ -3622,6 +3714,7 @@ namespace HISP.Server
|
|||
continue;
|
||||
if(entry.EnteredUser.LoggedinClient.LoggedIn)
|
||||
entry.EnteredUser.LoggedinClient.SendPacket(response);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6703,14 +6796,15 @@ namespace HISP.Server
|
|||
|
||||
|
||||
}
|
||||
public static void UpdateAreaForAll(int x, int y, bool ignoreMetaPrio=false)
|
||||
public static void UpdateAreaForAll(int x, int y, bool ignoreMetaPrio=false, User exceptMe=null)
|
||||
{
|
||||
foreach(GameClient client in ConnectedClients)
|
||||
{
|
||||
if (client.LoggedIn)
|
||||
if (client.LoggedinUser.X == x && client.LoggedinUser.Y == y)
|
||||
if(!client.LoggedinUser.MetaPriority || ignoreMetaPrio)
|
||||
UpdateArea(client);
|
||||
if(client.LoggedinUser != exceptMe)
|
||||
UpdateArea(client);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -115,6 +115,7 @@ namespace HISP.Server
|
|||
public const byte SWFMODULE_ARENA = 0x52;
|
||||
public const byte SWFMODULE_BRICKPOET = 0x5A;
|
||||
public const byte SWFMODULE_DRAWINGROOM = 0x5B;
|
||||
public const byte SWFMODULE_DRESSUPROOM = 0x5C;
|
||||
|
||||
public const byte DRAWINGROOM_GET_DRAWING = 0x14;
|
||||
public const byte DRAWINGROOM_SAVE = 0x15;
|
||||
|
@ -123,6 +124,8 @@ namespace HISP.Server
|
|||
public const byte BRICKPOET_LIST_ALL = 0x14;
|
||||
public const byte BRICKPOET_MOVE = 0x55;
|
||||
|
||||
public const byte DRESSUPROOM_LIST_ALL = 0x14;
|
||||
|
||||
public const byte WISH_MONEY = 0x31;
|
||||
public const byte WISH_ITEMS = 0x32;
|
||||
public const byte WISH_WORLDPEACE = 0x33;
|
||||
|
@ -208,17 +211,68 @@ namespace HISP.Server
|
|||
public const byte DIRECTION_TELEPORT = 4;
|
||||
public const byte DIRECTION_NONE = 10;
|
||||
|
||||
public static byte[] CreateForwardedSwfRequest(byte[] request)
|
||||
public static byte[] CreateDressupRoomPeiceMove(int peiceId, double x, double y, bool active)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ms.WriteByte(PacketBuilder.PACKET_SWFMODULE);
|
||||
ms.Write(request, 0x2, request.Length - 0x4);
|
||||
ms.WriteByte(PacketBuilder.PACKET_TERMINATOR);
|
||||
ms.WriteByte(PACKET_SWFMODULE);
|
||||
string packetStr = "";
|
||||
packetStr += peiceId.ToString() + "|";
|
||||
if (active)
|
||||
{
|
||||
packetStr += x.ToString() + "|";
|
||||
packetStr += y.ToString() + "|";
|
||||
}
|
||||
else
|
||||
{
|
||||
packetStr += "D|D|";
|
||||
}
|
||||
packetStr += "^";
|
||||
|
||||
byte[] packetBytes = Encoding.UTF8.GetBytes(packetStr);
|
||||
ms.Write(packetBytes, 0x00, packetBytes.Length);
|
||||
ms.WriteByte(PACKET_TERMINATOR);
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] response = ms.ToArray();
|
||||
ms.Dispose();
|
||||
return response;
|
||||
}
|
||||
public static byte[] CreateDressupRoomPeiceResponse(Dressup.DressupPeice[] dressupPeices)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ms.WriteByte(PACKET_SWFMODULE);
|
||||
string packetStr = "";
|
||||
foreach(Dressup.DressupPeice peice in dressupPeices)
|
||||
{
|
||||
if (!peice.Active)
|
||||
continue;
|
||||
|
||||
packetStr += peice.PeiceId.ToString() + "|";
|
||||
packetStr += peice.X.ToString() + "|";
|
||||
packetStr += peice.Y.ToString() + "|";
|
||||
packetStr += "^";
|
||||
}
|
||||
|
||||
byte[] packetBytes = Encoding.UTF8.GetBytes(packetStr);
|
||||
ms.Write(packetBytes, 0x00, packetBytes.Length);
|
||||
ms.WriteByte(PACKET_TERMINATOR);
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] response = ms.ToArray();
|
||||
ms.Dispose();
|
||||
return response;
|
||||
}
|
||||
|
||||
public static byte[] CreateForwardedSwfRequest(byte[] request)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ms.WriteByte(PACKET_SWFMODULE);
|
||||
ms.Write(request, 0x2, request.Length - 0x4);
|
||||
ms.WriteByte(PACKET_TERMINATOR);
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
byte[] response = ms.ToArray();
|
||||
ms.Dispose();
|
||||
return response;
|
||||
}
|
||||
|
||||
public static byte[] CreateBirdMap(int playerX, int playerY)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
|
@ -226,7 +280,7 @@ namespace HISP.Server
|
|||
int xstart = playerX - 24;
|
||||
int ystart = playerY - 15;
|
||||
|
||||
ms.WriteByte(PacketBuilder.PACKET_BIRDMAP);
|
||||
ms.WriteByte(PACKET_BIRDMAP);
|
||||
|
||||
for (int rely = 0; rely <= 30; rely++)
|
||||
{
|
||||
|
@ -261,7 +315,7 @@ namespace HISP.Server
|
|||
public static byte[] CreateDrawingUpdatePacket(string Drawing)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ms.WriteByte(PacketBuilder.PACKET_SWFMODULE);
|
||||
ms.WriteByte(PACKET_SWFMODULE);
|
||||
byte[] drawingBytes = Encoding.UTF8.GetBytes(Drawing);
|
||||
ms.Write(drawingBytes, 0x00, drawingBytes.Length);
|
||||
ms.WriteByte(PACKET_TERMINATOR);
|
||||
|
@ -272,8 +326,8 @@ namespace HISP.Server
|
|||
{
|
||||
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ms.WriteByte(PacketBuilder.PACKET_SWFMODULE);
|
||||
ms.WriteByte(PacketBuilder.BRICKPOET_MOVE);
|
||||
ms.WriteByte(PACKET_SWFMODULE);
|
||||
ms.WriteByte(BRICKPOET_MOVE);
|
||||
string packetStr = "|";
|
||||
packetStr += peice.Id + "|";
|
||||
packetStr += peice.X + "|";
|
||||
|
@ -289,7 +343,7 @@ namespace HISP.Server
|
|||
public static byte[] CreateBrickPoetListPacket(Brickpoet.PoetryPeice[] room)
|
||||
{
|
||||
MemoryStream ms = new MemoryStream();
|
||||
ms.WriteByte(PacketBuilder.PACKET_SWFMODULE);
|
||||
ms.WriteByte(PACKET_SWFMODULE);
|
||||
string packetStr = "";
|
||||
foreach(Brickpoet.PoetryPeice peice in room)
|
||||
{
|
||||
|
@ -307,7 +361,7 @@ namespace HISP.Server
|
|||
}
|
||||
byte[] packetBytes = Encoding.UTF8.GetBytes(packetStr);
|
||||
ms.Write(packetBytes, 0x00, packetBytes.Length);
|
||||
ms.WriteByte(PacketBuilder.PACKET_TERMINATOR);
|
||||
ms.WriteByte(PACKET_TERMINATOR);
|
||||
|
||||
ms.Seek(0x00, SeekOrigin.Begin);
|
||||
return ms.ToArray();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue