no message

This commit is contained in:
SilicaAndPina 2020-09-30 05:04:17 +13:00
parent e3a9560c7c
commit 1b9be5036e
9 changed files with 190 additions and 57 deletions

View file

@ -76,19 +76,28 @@ namespace Horse_Isle_Server
}
byte identifier = Packet[0];
if(!LoggedIn) // Must be either login or policy-file-request
if (!LoggedIn) // Must be either login or policy-file-request
{
if(Encoding.UTF8.GetString(Packet).StartsWith("<policy-file-request/>")) // Policy File Request
if (Encoding.UTF8.GetString(Packet).StartsWith("<policy-file-request/>")) // Policy File Request
{
Server.OnCrossdomainPolicyRequest(this);
}
switch(identifier)
switch (identifier)
{
case PacketBuilder.PACKET_LOGIN:
Server.OnLoginRequest(this,Packet);
Server.OnLoginRequest(this, Packet);
break;
}
}
}
else
{
switch (identifier)
{
case PacketBuilder.PACKET_LOGIN:
Server.OnUserInfoRequest(this, Packet);
break;
}
}
}
public void Disconnect()

View file

@ -17,6 +17,7 @@ namespace Horse_Isle_Server
string ExtTable = "CREATE TABLE UserExt(Id INT, X INT, Y INT, Money INT, BankBalance BIGINT,ProfilePage Text(1028), CharId INT)";
string MailTable = "CREATE TABLE Mailbox(IdTo INT, PlayerFrom TEXT(16),Subject TEXT(128), Message Text(1028), TimeSent INT)";
string WorldTable = "CREATE TABLE World(TimeStarted INT, Weather TEXT(64))";
string DroppedTable = "CREATE TABLE DroppedItems(X INT, Y INT, ItemID INT)";
try
{
@ -31,7 +32,6 @@ namespace Horse_Isle_Server
try
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = ExtTable;
sqlCommand.ExecuteNonQuery();
@ -53,6 +53,18 @@ namespace Horse_Isle_Server
Logger.WarnPrint(e.Message);
};
try
{
MySqlCommand sqlCommand = db.CreateCommand();
sqlCommand.CommandText = DroppedTable;
sqlCommand.ExecuteNonQuery();
}
catch (Exception e)
{
Logger.WarnPrint(e.Message);
};
try
{

View file

@ -5,32 +5,19 @@ using Newtonsoft.Json;
namespace Horse_Isle_Server
{
internal class Isle
{
public int StartX = 0;
public int EndX = 0;
public int StartY = 0;
public int EndY = 0;
public int Tileset = 0;
public string Name;
public Isle(int startx, int starty, int endx, int endy, int tileset, string name)
{
StartX = startx;
StartY = starty;
EndX = endx;
EndY = endy;
Tileset = tileset;
Name = name;
}
}
class Gamedata
{
public static List<Isle> Isles = new List<Isle>();
public static string TileFlags;
public static int NewUserStartX;
public static int NewUserStartY;
// Messages
public static string NewUserMessage;
public static string AreaMessage;
public static string NothingMessage;
public static string LoginMessage;
public static void ReadGamedata()
{
@ -46,25 +33,27 @@ namespace Horse_Isle_Server
for(int i = 0; i < totalIsles; i++)
{
int startx = gameData.isles[i].start_x;
int starty = gameData.isles[i].start_y;
int endx = gameData.isles[i].end_x;
int endy = gameData.isles[i].end_y;
int tileset = gameData.isles[i].tileset;
string name = gameData.isles[i].name;
World.Isle isle = new World.Isle();
isle.StartX = gameData.isles[i].start_x;
isle.StartY = gameData.isles[i].start_y;
isle.EndX = gameData.isles[i].end_x;
isle.EndY = gameData.isles[i].end_y;
isle.Tileset = gameData.isles[i].tileset;
isle.Name = gameData.isles[i].name;
Logger.DebugPrint("Registered Isle: " + name + " X " + startx + "-" + endx + " Y " + starty + "-" + endy + " tileset: " + tileset);
Isles.Add(new Isle(startx, starty, endx, endy, tileset, name));
Logger.DebugPrint("Registered Isle: " + isle.Name + " X " + isle.StartX + "-" + isle.EndX + " Y " + isle.StartY + "-" + isle.EndY + " tileset: " + isle.Tileset);
World.Isles.Add(isle);
}
NewUserMessage = gameData.new_user.starting_message;
Logger.DebugPrint("New User Message: " + NewUserMessage);
NewUserStartX = gameData.new_user.starting_x;
Logger.DebugPrint("New User Start X: " + NewUserStartX);
NewUserStartY = gameData.new_user.starting_y;
Logger.DebugPrint("New User Start Y: " + NewUserStartY);
LoginMessage = gameData.messages.login_format;
AreaMessage = gameData.messages.area_format;
NothingMessage = gameData.messages.nothing_message;
TileFlags = gameData.map_flags;
}
}

View file

@ -78,7 +78,9 @@
<Compile Include="Logger.cs" />
<Compile Include="ConfigReader.cs" />
<Compile Include="CrossDomainPolicy.cs" />
<Compile Include="Mailbox.cs" />
<Compile Include="Map.cs" />
<Compile Include="Messages.cs" />
<Compile Include="PacketBuilder.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />

View file

@ -17,10 +17,10 @@ namespace Horse_Isle_Server
if ((x > MapData.Width || x < 0) || (y > MapData.Height || y < 0)) // Outside map?
return 0x01;
if(overlay)
return oMapData.GetPixel(x,y).ToArgb() & Convert.ToInt32(0xFF000000);
if (overlay)
return oMapData.GetPixel(x, y).B;
else
return MapData.GetPixel(x, y).ToArgb() & Convert.ToInt32(0xFF000000);
return MapData.GetPixel(x, y).B;
}
public static void OpenMap()
@ -32,7 +32,7 @@ namespace Horse_Isle_Server
}
MapData = new Bitmap(ConfigReader.MapFile);
oMapData = new Bitmap(ConfigReader.MapFile);
oMapData = new Bitmap(ConfigReader.OverlayMapFile);
}
}
}

View file

@ -20,6 +20,11 @@ namespace Horse_Isle_Server
public const byte PACKET_USERINFO = 0x81;
public const byte PACKET_WORLD = 0x7A;
public const byte PACKET_BASE_STATS = 0x7B;
public const byte PACKET_PLACE_INFO = 0x1E;
public const byte PACKET_AREA_DEFS = 0x79;
public const byte PACKET_TILE_FLAGS = 0x75;
public const byte AREA_SEPERATOR = 0x5E;
private const byte CHAT_BOTTOM_LEFT = 0x14;
private const byte CHAT_BOTTOM_RIGHT = 0x15;
@ -71,14 +76,19 @@ namespace Horse_Isle_Server
direction -= 20;
}
int ystart = y - 3;
int xstart = x - 2;
if (direction == 4)
{
for(int rely = y - 3; rely < rely + 9; rely++)
for(int rely = 0; rely <= 9; rely++)
{
for (int relx = x - 2; relx < relx + 12; relx++)
for (int relx = 0; relx <= 12; relx++)
{
int tileId = Map.GetTileId(relx, rely, false);
int otileId = Map.GetTileId(relx, rely, true);
int tileId = Map.GetTileId(xstart + relx, ystart + rely, false);
int otileId = Map.GetTileId(xstart + relx, ystart + rely, true);
if (tileId == 290)
tileId -= 100;
@ -94,6 +104,24 @@ namespace Horse_Isle_Server
ms.WriteByte(PACKET_TERMINATOR);
ms.Seek(0x00, SeekOrigin.Begin);
byte[] Packet = ms.ToArray();
ms.Dispose();
return Packet;
}
public static byte[] CreatePlaceInfo(string formattedText)
{
byte[] strBytes = Encoding.UTF8.GetBytes(formattedText);
MemoryStream ms = new MemoryStream();
ms.WriteByte(PACKET_PLACE_INFO);
ms.Write(strBytes, 0x00, strBytes.Length);
ms.WriteByte(PACKET_TERMINATOR);
ms.Seek(0x00, SeekOrigin.Begin);
byte[] Packet = ms.ToArray();
ms.Dispose();
@ -120,10 +148,14 @@ namespace Horse_Isle_Server
return Packet;
}
public static byte[] CreateAreaMessage(int x, int y)
{
string locationStr = Messages.LocationData(x, y);
return CreatePlaceInfo(locationStr);
}
public static byte[] CreateLoginMessage(string username)
{
string formattedStr = Gamedata.NewUserMessage.Replace("%USERNAME%", username);
string formattedStr = Messages.LoginMessage(username);
return CreateChat(formattedStr,CHAT_BOTTOM_RIGHT);
}
@ -153,6 +185,41 @@ namespace Horse_Isle_Server
return Packet;
}
public static byte[] CreateIsleData(World.Isle[] isles)
{
MemoryStream ms = new MemoryStream();
ms.WriteByte(PACKET_AREA_DEFS);
foreach(World.Isle isle in isles)
{
byte[] strBytes = Encoding.UTF8.GetBytes(isle.Name);
ms.WriteByte(AREA_SEPERATOR);
ms.WriteByte((byte)((isle.StartX / 64) + 20));
ms.WriteByte((byte)((isle.StartX % 64) + 20));
ms.WriteByte((byte)((isle.EndX / 64) + 20));
ms.WriteByte((byte)((isle.EndX % 64) + 20));
ms.WriteByte((byte)((isle.StartY / 64) + 20));
ms.WriteByte((byte)((isle.StartY % 64) + 20));
ms.WriteByte((byte)((isle.EndY / 64) + 20));
ms.WriteByte((byte)((isle.EndY % 64) + 20));
ms.WriteByte((byte)isle.Tileset.ToString()[0]);
ms.Write(strBytes, 0x00, strBytes.Length);
}
ms.WriteByte(PACKET_TERMINATOR);
ms.Seek(0x00, SeekOrigin.Begin);
byte[] Packet = ms.ToArray();
ms.Dispose();
return Packet;
}
public static byte[] CreateBaseStats(int money, int playerCount, int mail)
{
byte[] moneyStrBytes = Encoding.UTF8.GetBytes(money.ToString());
@ -175,6 +242,23 @@ namespace Horse_Isle_Server
return Packet;
}
public static byte[] CreateTileFlags(string tileFlags)
{
MemoryStream ms = new MemoryStream();
ms.WriteByte(PACKET_TILE_FLAGS);
byte[] strBytes = Encoding.UTF8.GetBytes(tileFlags);
ms.Write(strBytes, 0x00, strBytes.Length);
ms.WriteByte(PACKET_TERMINATOR);
ms.Seek(0x00, SeekOrigin.Begin);
byte[] Packet = ms.ToArray();
ms.Dispose();
return Packet;
}
public static byte[] CreateSecCode(byte[] SecCodeSeed, int SecCodeInc, bool Admin, bool Moderator)
{
MemoryStream ms = new MemoryStream();
@ -219,15 +303,23 @@ namespace Horse_Isle_Server
timestamp += time.minutes;
byte[] WorldData = CreateWorldData(timestamp, time.days, time.year, World.GetWeather());
ms.Write(WorldData, 0x00, LoginMessage.Length);
ms.Write(WorldData, 0x00, WorldData.Length);
byte[] SecCodePacket = CreateSecCode(user.SecCodeSeeds, user.SecCodeInc, user.Administrator, user.Moderator);
ms.Write(SecCodePacket, 0x00, SecCodePacket.Length);
byte[] BaseStatsPacketData = CreateBaseStats(user.Money, Server.GetNumberOfPlayers(), user.MailBox.MailCount);
ms.Write(BaseStatsPacketData, 0x00, BaseStatsPacketData.Length);
byte[] AreaMessage = CreateAreaMessage(user.X,user.Y);
ms.Write(AreaMessage, 0x00, AreaMessage.Length);
byte[] IsleData = CreateIsleData(World.Isles.ToArray());
ms.Write(IsleData, 0x00, IsleData.Length);
byte[] TileFlags = CreateTileFlags(Gamedata.TileFlags);
ms.Write(TileFlags, 0x00, TileFlags.Length);
ms.Seek(0x00, SeekOrigin.Begin);
byte[] Packet = ms.ToArray();
ms.Dispose();

View file

@ -23,6 +23,17 @@ namespace Horse_Isle_Server
sender.SendPacket(crossDomainPolicyResponse); // Send to client.
}
public static void OnUserInfoRequest(Client sender, byte[] packet)
{
if (!sender.LoggedIn)
{
Logger.ErrorPrint(sender.RemoteIp + " Requested user information when not logged in.");
return;
}
Logger.DebugPrint(sender.RemoteIp + " Requesting user information.");
byte[] userInfoPackets = PacketBuilder.CreateUserInfo(sender);
sender.SendPacket(userInfoPackets);
}
public static void OnLoginRequest(Client sender, byte[] packet)
{
Logger.DebugPrint("Login request received from: " + sender.RemoteIp);
@ -66,14 +77,6 @@ namespace Horse_Isle_Server
sender.SendPacket(ResponsePacket);
}
}
else
{
if(!sender.LoggedIn)
{
Logger.ErrorPrint(sender.RemoteIp + " Requested user information when not logged in.");
return;
}
}
}

View file

@ -9,7 +9,16 @@ namespace Horse_Isle_Server
class World
{
public struct Isle
{
public int StartX;
public int EndX;
public int StartY;
public int EndY;
public int Tileset;
public string Name;
}
public struct Time
{
public int minutes;
@ -19,6 +28,7 @@ namespace Horse_Isle_Server
}
public const int MINUTE = 4320;
public static List<Isle> Isles = new List<Isle>();
public static Time GetGameTime()
{
int epoch = Database.GetServerCreationTime();
@ -44,6 +54,22 @@ namespace Horse_Isle_Server
return time;
}
public static Isle GetIsle(int x, int y)
{
foreach(Isle isle in Isles)
{
if (isle.StartX <= x && isle.EndX >= x && isle.StartY <= y && isle.EndY >= y)
{
return isle;
}
}
throw new KeyNotFoundException("x,y not in an isle!");
}
public static int[] GetDroppedItems(int x, int y)
{
return new int[] { }; // Not implemented yet.
}
public static string GetWeather()
{
return Database.GetWorldWeather();

Binary file not shown.

After

Width:  |  Height:  |  Size: 284 KiB