mirror of
https://github.com/islehorse/HISP.git
synced 2025-06-04 04:47:09 +12:00
Add Feature pt1
This commit is contained in:
parent
a184e4d735
commit
092534e331
131 changed files with 3113 additions and 1418 deletions
137
HorseIsleServer/LibHISP/Server/ConfigReader.cs
Normal file
137
HorseIsleServer/LibHISP/Server/ConfigReader.cs
Normal file
|
@ -0,0 +1,137 @@
|
|||
using HISP.Properties;
|
||||
using System.IO;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
|
||||
public class ConfigReader
|
||||
{
|
||||
public static int Port = 12321;
|
||||
public static string BindIP = "0.0.0.0";
|
||||
|
||||
public static string DatabaseIP = "127.0.0.1";
|
||||
public static string DatabaseName = "game1";
|
||||
public static string DatabaseUsername = "root";
|
||||
public static string DatabasePassword = "test123";
|
||||
|
||||
public static int DatabasePort = 3306;
|
||||
public static int IntrestRate = 3333;
|
||||
public static string Motd = "April 11, 2020. New breed, Camarillo White Horse. Two new quests.";
|
||||
public static string MapFile = "HI1.MAP";
|
||||
public static string GameDataFile = "gamedata.json";
|
||||
public static string CrossDomainPolicyFile = "CrossDomainPolicy.xml";
|
||||
|
||||
public static int LogLevel = 4;
|
||||
|
||||
public static bool SqlLite = false;
|
||||
public static bool EnableSpamFilter = true;
|
||||
public static bool AllUsersSubbed = false;
|
||||
public static bool FixOfficalBugs = false;
|
||||
public static bool BadWords = true;
|
||||
public static bool DoCorrections = true;
|
||||
public static bool DoNonViolations = true;
|
||||
|
||||
public static string ConfigurationFileName = "server.properties";
|
||||
public static void OpenConfig()
|
||||
{
|
||||
if (!File.Exists(ConfigurationFileName))
|
||||
{
|
||||
Logger.WarnPrint(ConfigurationFileName+" not found! writing default.");
|
||||
File.WriteAllText(ConfigurationFileName, Resources.DefaultServerProperties);
|
||||
Logger.WarnPrint("! Its very likely database connection will fail...");
|
||||
}
|
||||
|
||||
string[] configFile = File.ReadAllLines(ConfigurationFileName);
|
||||
foreach (string setting in configFile)
|
||||
{
|
||||
/*
|
||||
* Avoid crashing.
|
||||
*/
|
||||
if (setting.Length < 1)
|
||||
continue;
|
||||
if (setting[0] == '#')
|
||||
continue;
|
||||
if (!setting.Contains("="))
|
||||
continue;
|
||||
|
||||
string[] dataPair = setting.Split('=');
|
||||
|
||||
string key = dataPair[0];
|
||||
string data = dataPair[1];
|
||||
/*
|
||||
* Parse configuration file
|
||||
*/
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case "port":
|
||||
Port = int.Parse(data);
|
||||
break;
|
||||
case "ip":
|
||||
BindIP = data;
|
||||
break;
|
||||
case "db_ip":
|
||||
DatabaseIP = data;
|
||||
break;
|
||||
case "db_username":
|
||||
DatabaseUsername = data;
|
||||
break;
|
||||
case "db_password":
|
||||
DatabasePassword = data;
|
||||
break;
|
||||
case "db_name":
|
||||
DatabaseName = data;
|
||||
break;
|
||||
case "db_port":
|
||||
DatabasePort = int.Parse(data);
|
||||
break;
|
||||
case "map":
|
||||
MapFile = data;
|
||||
break;
|
||||
case "motd":
|
||||
Motd = data;
|
||||
break;
|
||||
case "gamedata":
|
||||
GameDataFile = data;
|
||||
break;
|
||||
case "crossdomain":
|
||||
CrossDomainPolicyFile = data;
|
||||
break;
|
||||
case "all_users_subscribed":
|
||||
AllUsersSubbed = data == "true";
|
||||
break;
|
||||
case "enable_corrections":
|
||||
DoCorrections = data == "true";
|
||||
break;
|
||||
case "sql_lite":
|
||||
SqlLite = data == "true";
|
||||
break;
|
||||
case "enable_non_violation_check":
|
||||
DoNonViolations = data == "true";
|
||||
break;
|
||||
case "enable_spam_filter":
|
||||
EnableSpamFilter = data == "true";
|
||||
break;
|
||||
case "fix_offical_bugs":
|
||||
FixOfficalBugs = data == "true";
|
||||
break;
|
||||
case "enable_word_filter":
|
||||
BadWords = data == "true";
|
||||
break;
|
||||
case "intrest_rate":
|
||||
IntrestRate = int.Parse(data);
|
||||
break;
|
||||
case "log_level":
|
||||
LogLevel = int.Parse(data);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
6134
HorseIsleServer/LibHISP/Server/Database.cs
Normal file
6134
HorseIsleServer/LibHISP/Server/Database.cs
Normal file
File diff suppressed because it is too large
Load diff
594
HorseIsleServer/LibHISP/Server/GameClient.cs
Normal file
594
HorseIsleServer/LibHISP/Server/GameClient.cs
Normal file
|
@ -0,0 +1,594 @@
|
|||
using System;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Collections.Generic;
|
||||
using HISP.Player;
|
||||
using HISP.Game;
|
||||
using HISP.Game.Horse;
|
||||
using HISP.Game.Events;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
public class GameClient
|
||||
{
|
||||
private static List<GameClient> connectedClients = new List<GameClient>();
|
||||
public static GameClient[] ConnectedClients // Done to prevent Enumerator Changed errors.
|
||||
{
|
||||
get
|
||||
{
|
||||
return connectedClients.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
public Socket ClientSocket;
|
||||
public string RemoteIp;
|
||||
private bool loggedIn = false;
|
||||
public bool LoggedIn
|
||||
{
|
||||
get
|
||||
{
|
||||
bool login = loggedIn;
|
||||
if (LoggedinUser == null)
|
||||
return false;
|
||||
if (LoggedinUser.LoggedinClient == null)
|
||||
return false;
|
||||
return login;
|
||||
}
|
||||
set
|
||||
{
|
||||
loggedIn = value;
|
||||
}
|
||||
}
|
||||
public User LoggedinUser;
|
||||
|
||||
private Timer keepAliveTimer;
|
||||
private Timer timeoutTimer;
|
||||
|
||||
private Timer warnTimer;
|
||||
private Timer kickTimer;
|
||||
private Timer minuteTimer;
|
||||
|
||||
private bool isDisconnecting = false;
|
||||
|
||||
private int timeoutInterval = 95 * 1000;
|
||||
|
||||
private int totalMinutesElapsed = 0;
|
||||
private int oneMinute = 60 * 1000;
|
||||
private int warnInterval = GameServer.IdleWarning * 60 * 1000; // Time before showing a idle warning
|
||||
private int kickInterval = GameServer.IdleTimeout * 60 * 1000; // Time before kicking for inactivity
|
||||
|
||||
private List<byte> currentPacket = new List<byte>();
|
||||
private byte[] workBuffer = new byte[0x8000];
|
||||
|
||||
public GameClient(Socket clientSocket)
|
||||
{
|
||||
clientSocket.SendTimeout = 10 * 1000; // 10sec
|
||||
clientSocket.ReceiveTimeout = 10 * 1000; // 10sec
|
||||
|
||||
ClientSocket = clientSocket;
|
||||
RemoteIp = clientSocket.RemoteEndPoint.ToString();
|
||||
|
||||
if (RemoteIp.Contains(":"))
|
||||
RemoteIp = RemoteIp.Substring(0, RemoteIp.IndexOf(":"));
|
||||
|
||||
Logger.DebugPrint("Client connected @ " + RemoteIp);
|
||||
|
||||
kickTimer = new Timer(new TimerCallback(kickTimerTick), null, kickInterval, kickInterval);
|
||||
warnTimer = new Timer(new TimerCallback(warnTimerTick), null, warnInterval, warnInterval);
|
||||
minuteTimer = new Timer(new TimerCallback(minuteTimerTick), null, oneMinute, oneMinute);
|
||||
|
||||
connectedClients.Add(this);
|
||||
|
||||
SocketAsyncEventArgs evt = new SocketAsyncEventArgs();
|
||||
evt.Completed += receivePackets;
|
||||
evt.SetBuffer(workBuffer, 0, workBuffer.Length);
|
||||
if (!clientSocket.ReceiveAsync(evt))
|
||||
receivePackets(null, evt);
|
||||
}
|
||||
|
||||
public static void CreateClient(object sender, SocketAsyncEventArgs e)
|
||||
{
|
||||
do
|
||||
{
|
||||
Socket eSocket = e.AcceptSocket;
|
||||
if(eSocket != null)
|
||||
new GameClient(eSocket);
|
||||
e.AcceptSocket = null;
|
||||
} while (!GameServer.ServerSocket.AcceptAsync(e));
|
||||
}
|
||||
private void timeoutTimerTick(object state)
|
||||
{
|
||||
if (this.LoggedIn)
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
if (this.isDisconnecting)
|
||||
return;
|
||||
this.isDisconnecting = true;
|
||||
|
||||
// Close Socket
|
||||
if (ClientSocket != null)
|
||||
{
|
||||
ClientSocket.Close();
|
||||
ClientSocket.Dispose();
|
||||
ClientSocket = null;
|
||||
}
|
||||
|
||||
|
||||
// Stop Timers
|
||||
if (timeoutTimer != null)
|
||||
{
|
||||
timeoutTimer.Dispose();
|
||||
timeoutTimer = null;
|
||||
}
|
||||
if (keepAliveTimer != null)
|
||||
{
|
||||
keepAliveTimer.Dispose();
|
||||
keepAliveTimer = null;
|
||||
}
|
||||
if (warnTimer != null)
|
||||
{
|
||||
warnTimer.Dispose();
|
||||
warnTimer = null;
|
||||
}
|
||||
if (kickTimer != null)
|
||||
{
|
||||
kickTimer.Dispose();
|
||||
kickTimer = null;
|
||||
}
|
||||
|
||||
// Call OnDisconnect
|
||||
|
||||
connectedClients.Remove(this);
|
||||
GameServer.OnDisconnect(this);
|
||||
LoggedIn = false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void receivePackets(object sender, SocketAsyncEventArgs e)
|
||||
{
|
||||
do
|
||||
{
|
||||
// HI1 Packets are terminates by 0x00 so we have to read until we receive that terminator
|
||||
|
||||
if (isDisconnecting ||
|
||||
ClientSocket == null ||
|
||||
e.BytesTransferred <= 0 ||
|
||||
!ClientSocket.Connected ||
|
||||
e.SocketError != SocketError.Success)
|
||||
{
|
||||
Disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
int availble = e.BytesTransferred;
|
||||
if (availble >= 1) // More than 1 byte transfered..
|
||||
{
|
||||
|
||||
for (int i = 0; i < availble; i++)
|
||||
{
|
||||
currentPacket.Add(e.Buffer[i]);
|
||||
if (e.Buffer[i] == PacketBuilder.PACKET_TERMINATOR) // Read until \0...
|
||||
{
|
||||
parsePackets(currentPacket.ToArray());
|
||||
currentPacket.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (availble == 0)
|
||||
Disconnect();
|
||||
|
||||
if (isDisconnecting || ClientSocket == null)
|
||||
return;
|
||||
|
||||
|
||||
} while (!ClientSocket.ReceiveAsync(e));
|
||||
|
||||
}
|
||||
|
||||
private void keepAliveTick(object state)
|
||||
{
|
||||
Logger.DebugPrint("Sending keep-alive packet to " + LoggedinUser.Username);
|
||||
byte[] updatePacket = PacketBuilder.CreateKeepAlive();
|
||||
SendPacket(updatePacket);
|
||||
if(!isDisconnecting && keepAliveTimer != null) // wtf how is this still a problem?
|
||||
keepAliveTimer.Change(oneMinute, oneMinute);
|
||||
}
|
||||
private void minuteTimerTick(object state)
|
||||
{
|
||||
totalMinutesElapsed++;
|
||||
if (LoggedIn)
|
||||
{
|
||||
|
||||
GameServer.UpdatePlayer(this);
|
||||
|
||||
LoggedinUser.CanUseAdsChat = true;
|
||||
LoggedinUser.FreeMinutes -= 1;
|
||||
|
||||
GameServer.DoItemPurchases(this);
|
||||
|
||||
if (totalMinutesElapsed % 2 == 0)
|
||||
{
|
||||
LoggedinUser.TotalGlobalChatMessages++;
|
||||
}
|
||||
|
||||
if (LoggedinUser.FreeMinutes <= 0)
|
||||
{
|
||||
LoggedinUser.FreeMinutes = 0;
|
||||
if (!LoggedinUser.Subscribed && !LoggedinUser.Moderator && !LoggedinUser.Administrator)
|
||||
{
|
||||
Kick(Messages.KickReasonNoTime);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Those fun messages when u have been playing for awhile.
|
||||
if (totalMinutesElapsed % (2 * 60) == 0)
|
||||
{
|
||||
string ptMessage = Messages.RngMessages[GameServer.RandomNumberGenerator.Next(0, Messages.RngMessages.Length)];
|
||||
byte[] playTimeMessage = PacketBuilder.CreateChat(Messages.FormatPlaytimeMessage(totalMinutesElapsed / 60) + ptMessage, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
SendPacket(playTimeMessage);
|
||||
}
|
||||
|
||||
|
||||
if (GameServer.RandomNumberGenerator.Next(0, 100) == 59) // RANDOM EVENT HAS OCCURED!
|
||||
{
|
||||
RandomEvent.ExecuteRandomEvent(LoggedinUser);
|
||||
}
|
||||
|
||||
bool gotoPrision = false;
|
||||
foreach(HorseInstance horse in LoggedinUser.HorseInventory.HorseList)
|
||||
{
|
||||
if (totalMinutesElapsed % 2 == 0)
|
||||
{
|
||||
horse.BasicStats.Thirst--;
|
||||
horse.BasicStats.Hunger--;
|
||||
|
||||
if (horse.BasicStats.Thirst <= 0 && horse.BasicStats.Hunger <= 0)
|
||||
{
|
||||
horse.BasicStats.Health -= 5;
|
||||
if(horse.BasicStats.Hunger <= 0)
|
||||
{
|
||||
gotoPrision = true; // Goto jail, go directly to jail, do not pass go, do not collect 200$
|
||||
|
||||
horse.BasicStats.Health = 10;
|
||||
horse.BasicStats.Hunger = 500;
|
||||
horse.BasicStats.Thirst = 500;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(horse.Leaser > 0)
|
||||
{
|
||||
horse.LeaseTime--;
|
||||
|
||||
if (horse.LeaseTime <= 0)
|
||||
{
|
||||
int tpX = 0;
|
||||
int tpY = 0;
|
||||
if(horse.Breed.Type == "unicorn" || horse.Breed.Type == "pegasus")
|
||||
{
|
||||
foreach (World.SpecialTile tile in World.SpecialTiles)
|
||||
{
|
||||
if (tile.Code == null)
|
||||
continue;
|
||||
|
||||
if (tile.Code.StartsWith("HORSELEASER-"))
|
||||
{
|
||||
int id = int.Parse(tile.Code.Split("-")[1]);
|
||||
if (horse.Leaser == id)
|
||||
{
|
||||
string msg = Messages.FormatHorseReturnedToUniter(horse.Breed.Name);
|
||||
if (horse.Breed.Type == "pegasus")
|
||||
msg = Messages.HorseLeaserReturnedToUniterPegasus;
|
||||
|
||||
byte[] youWereTeleportedToUniter = PacketBuilder.CreateChat(msg, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
SendPacket(youWereTeleportedToUniter);
|
||||
|
||||
tpX = tile.X;
|
||||
tpY = tile.Y;
|
||||
|
||||
if(tile.ExitX != 0 && tile.ExitY != 0)
|
||||
{
|
||||
tpX = tile.ExitX;
|
||||
tpY = tile.ExitY;
|
||||
}
|
||||
else
|
||||
{
|
||||
tpY++;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
byte[] horseReturned = PacketBuilder.CreateChat(Messages.FormatHorseReturnedToOwner(horse.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
SendPacket(horseReturned);
|
||||
|
||||
if(tpX != 0 && tpY != 0)
|
||||
LoggedinUser.Teleport(tpX, tpY);
|
||||
|
||||
|
||||
if (LoggedinUser.CurrentlyRidingHorse != null)
|
||||
{
|
||||
if(LoggedinUser.CurrentlyRidingHorse.RandomId == horse.RandomId)
|
||||
{
|
||||
GameServer.StopRidingHorse(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(LoggedinUser.LastViewedHorse != null)
|
||||
{
|
||||
if(LoggedinUser.LastViewedHorse.RandomId == horse.RandomId)
|
||||
{
|
||||
LoggedinUser.LastViewedHorse = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LoggedinUser.HorseInventory.DeleteHorse(horse);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if(gotoPrision)
|
||||
{
|
||||
byte[] sendToPrision = PacketBuilder.CreateChat(Messages.YouWereSentToPrisionIsle, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
SendPacket(sendToPrision);
|
||||
LoggedinUser.Teleport(45, 35);
|
||||
}
|
||||
|
||||
|
||||
if (totalMinutesElapsed % 5 == 0)
|
||||
LoggedinUser.Thirst--;
|
||||
|
||||
if (totalMinutesElapsed % 15 == 0)
|
||||
LoggedinUser.Hunger--;
|
||||
|
||||
if (totalMinutesElapsed % 15 == 0)
|
||||
LoggedinUser.Tiredness--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!isDisconnecting)
|
||||
minuteTimer.Change(oneMinute, oneMinute);
|
||||
|
||||
}
|
||||
|
||||
private void warnTimerTick(object state)
|
||||
{
|
||||
Logger.DebugPrint("Sending inactivity warning to: " + RemoteIp);
|
||||
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatIdleWarningMessage(), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
SendPacket(chatPacket);
|
||||
if (LoggedIn)
|
||||
LoggedinUser.Idle = true;
|
||||
}
|
||||
|
||||
private void kickTimerTick(object state)
|
||||
{
|
||||
Kick(Messages.FormatIdleKickMessage());
|
||||
}
|
||||
|
||||
public void Login(int id)
|
||||
{
|
||||
/*
|
||||
* Check for duplicate user
|
||||
* and disconnect them.
|
||||
*/
|
||||
foreach (GameClient Client in GameClient.ConnectedClients)
|
||||
{
|
||||
if (Client.LoggedIn)
|
||||
{
|
||||
if (Client.LoggedinUser.Id == id)
|
||||
Client.Kick(Messages.KickReasonDuplicateLogin);
|
||||
}
|
||||
}
|
||||
|
||||
LoggedinUser = new User(this, id);
|
||||
LoggedIn = true;
|
||||
|
||||
Database.SetIpAddress(id, RemoteIp);
|
||||
Database.SetLoginCount(id, Database.GetLoginCount(id) + 1);
|
||||
|
||||
keepAliveTimer = new Timer(new TimerCallback(keepAliveTick), null, oneMinute, oneMinute);
|
||||
timeoutTimer = new Timer(new TimerCallback(timeoutTimerTick), null, timeoutInterval, timeoutInterval);
|
||||
}
|
||||
|
||||
private void parsePackets(byte[] Packet)
|
||||
{
|
||||
if (Packet.Length < 1)
|
||||
{
|
||||
Logger.ErrorPrint("Received an invalid packet (size: "+Packet.Length+")");
|
||||
}
|
||||
byte identifier = Packet[0];
|
||||
|
||||
/*
|
||||
* Every time ive tried to fix this properly by just checking if its null or something
|
||||
* it keeps happening, so now im just going to catch the exception
|
||||
* and hope it works.
|
||||
*/
|
||||
try
|
||||
{
|
||||
if (LoggedIn)
|
||||
{
|
||||
if (timeoutTimer != null)
|
||||
timeoutTimer.Change(timeoutInterval, timeoutInterval); // Reset time before timing out
|
||||
else
|
||||
return;
|
||||
|
||||
if (keepAliveTimer != null && identifier != PacketBuilder.PACKET_KEEP_ALIVE)
|
||||
{
|
||||
if (LoggedIn)
|
||||
LoggedinUser.Idle = false;
|
||||
keepAliveTimer.Change(oneMinute, oneMinute);
|
||||
}
|
||||
else
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (kickTimer != null && identifier != PacketBuilder.PACKET_KEEP_ALIVE)
|
||||
kickTimer.Change(kickInterval, kickInterval);
|
||||
else
|
||||
return;
|
||||
|
||||
if (warnTimer != null && identifier != PacketBuilder.PACKET_KEEP_ALIVE)
|
||||
warnTimer.Change(warnInterval, warnInterval);
|
||||
else
|
||||
return;
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Put packet handling in a try/catch
|
||||
* this prevents the entire server from crashing
|
||||
* if theres an error in handling a particular packet.
|
||||
*/
|
||||
try
|
||||
{
|
||||
if (!LoggedIn) // Must be either login or policy-file-request
|
||||
{
|
||||
switch (identifier)
|
||||
{
|
||||
case PacketBuilder.PACKET_FLASH_XML_CROSSDOMAIN:
|
||||
GameServer.OnCrossdomainPolicyRequest(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_LOGIN:
|
||||
GameServer.OnLoginRequest(this, Packet);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (identifier)
|
||||
{
|
||||
case PacketBuilder.PACKET_LOGIN:
|
||||
GameServer.OnUserInfoRequest(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_MOVE:
|
||||
GameServer.OnMovementPacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_PLAYERINFO:
|
||||
GameServer.OnPlayerInfoPacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_PLAYER:
|
||||
GameServer.OnProfilePacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_CHAT:
|
||||
GameServer.OnChatPacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_CLICK:
|
||||
GameServer.OnClickPacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_KEEP_ALIVE:
|
||||
GameServer.OnKeepAlive(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_TRANSPORT:
|
||||
GameServer.OnTransportUsed(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_INVENTORY:
|
||||
GameServer.OnInventoryRequested(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_DYNAMIC_BUTTON:
|
||||
GameServer.OnDynamicButtonPressed(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_DYNAMIC_INPUT:
|
||||
GameServer.OnDynamicInputReceived(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_ITEM_INTERACTION:
|
||||
GameServer.OnItemInteraction(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_ARENA_SCORE:
|
||||
GameServer.OnArenaScored(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_QUIT:
|
||||
GameServer.OnQuitPacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_NPC:
|
||||
GameServer.OnNpcInteraction(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_BIRDMAP:
|
||||
GameServer.OnBirdMapRequested(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_SWFMODULE:
|
||||
GameServer.OnSwfModuleCommunication(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_HORSE:
|
||||
GameServer.OnHorseInteraction(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_WISH:
|
||||
GameServer.OnWish(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_RANCH:
|
||||
GameServer.OnRanchPacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_AUCTION:
|
||||
GameServer.OnAuctionPacket(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_PLAYER_INTERACTION:
|
||||
GameServer.OnPlayerInteration(this, Packet);
|
||||
break;
|
||||
case PacketBuilder.PACKET_SOCIALS:
|
||||
GameServer.OnSocialPacket(this, Packet);
|
||||
break;
|
||||
default:
|
||||
Logger.ErrorPrint("Unimplemented Packet: " + BitConverter.ToString(Packet).Replace('-', ' '));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Logger.ErrorPrint("Unhandled Exception: " + e.ToString() + "\n" + e.Message + "\n" + e.StackTrace);
|
||||
|
||||
Kick("Unhandled Exception: " + e.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
public void Kick(string Reason)
|
||||
{
|
||||
byte[] kickPacket = PacketBuilder.CreateKickMessage(Reason);
|
||||
SendPacket(kickPacket);
|
||||
Disconnect();
|
||||
|
||||
Logger.InfoPrint("CLIENT: "+RemoteIp+" KICKED for: "+Reason);
|
||||
}
|
||||
|
||||
public void SendPacket(byte[] PacketData)
|
||||
{
|
||||
try
|
||||
{
|
||||
ClientSocket.Send(PacketData);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
2142
HorseIsleServer/LibHISP/Server/GameDataJson.cs
Normal file
2142
HorseIsleServer/LibHISP/Server/GameDataJson.cs
Normal file
File diff suppressed because it is too large
Load diff
8271
HorseIsleServer/LibHISP/Server/GameServer.cs
Normal file
8271
HorseIsleServer/LibHISP/Server/GameServer.cs
Normal file
File diff suppressed because it is too large
Load diff
46
HorseIsleServer/LibHISP/Server/Logger.cs
Normal file
46
HorseIsleServer/LibHISP/Server/Logger.cs
Normal file
|
@ -0,0 +1,46 @@
|
|||
using System;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
public class Logger
|
||||
{
|
||||
private static void defaultCallbackFunc(string txt)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
private static Action<string> logFunction = defaultCallbackFunc;
|
||||
|
||||
|
||||
public static void SetCallback(Action<string> callback)
|
||||
{
|
||||
logFunction = callback;
|
||||
}
|
||||
|
||||
public static void ErrorPrint(string text)
|
||||
{
|
||||
if (ConfigReader.LogLevel >= 1)
|
||||
logFunction("[ERROR] " + text);
|
||||
}
|
||||
public static void WarnPrint(string text)
|
||||
{
|
||||
if (ConfigReader.LogLevel >= 2)
|
||||
logFunction("[WARN] " + text);
|
||||
}
|
||||
public static void HackerPrint(string text)
|
||||
{
|
||||
if (ConfigReader.LogLevel >= 3)
|
||||
logFunction("[HACK] " + text);
|
||||
}
|
||||
public static void InfoPrint(string text)
|
||||
{
|
||||
if (ConfigReader.LogLevel >= 4)
|
||||
logFunction("[INFO] " + text);
|
||||
}
|
||||
public static void DebugPrint(string text)
|
||||
{
|
||||
if (ConfigReader.LogLevel >= 5)
|
||||
logFunction("[DEBUG] " + text);
|
||||
}
|
||||
}
|
||||
}
|
1005
HorseIsleServer/LibHISP/Server/PacketBuilder.cs
Normal file
1005
HorseIsleServer/LibHISP/Server/PacketBuilder.cs
Normal file
File diff suppressed because it is too large
Load diff
55
HorseIsleServer/LibHISP/Server/ServerVersion.cs
Normal file
55
HorseIsleServer/LibHISP/Server/ServerVersion.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using HISP.Properties;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
public class ServerVersion
|
||||
{
|
||||
public static int MAJOR = 1;
|
||||
public static int MINOR = 3;
|
||||
public static string PRODUCT = "HISP";
|
||||
|
||||
public static string GetArchitecture()
|
||||
{
|
||||
#if ARCH_ANYCPU
|
||||
return "ANYCPU";
|
||||
#elif ARCH_X86_64
|
||||
return "x86_64";
|
||||
#elif ARCH_X86
|
||||
return "x86";
|
||||
#elif ARCH_ARM
|
||||
return "ARM";
|
||||
#elif ARCH_ARM64
|
||||
return "ARM64";
|
||||
#else
|
||||
return "UNK_ARCH";
|
||||
#endif
|
||||
}
|
||||
public static string GetPlatform()
|
||||
{
|
||||
#if OS_DEBUG
|
||||
return "DEBUG";
|
||||
#elif OS_WINDOWS
|
||||
return "WINDOWS";
|
||||
#elif OS_LINUX
|
||||
return "LINUX";
|
||||
#elif OS_MACOS
|
||||
return "MACOS";
|
||||
#else
|
||||
return "UNK_PLATFORM";
|
||||
#endif
|
||||
|
||||
}
|
||||
public static string GetVersionString()
|
||||
{
|
||||
return "v" + MAJOR.ToString() + "." + MINOR.ToString();
|
||||
}
|
||||
public static string GetCommitHash(int TotalBytes)
|
||||
{
|
||||
return Resources.GitCommit.Substring(0, TotalBytes);
|
||||
}
|
||||
public static string GetBuildString()
|
||||
{
|
||||
return PRODUCT + " " + GetVersionString() + " @" + GetCommitHash(7) + "; (" + GetArchitecture() + "; " + GetPlatform() + ")";
|
||||
}
|
||||
}
|
||||
}
|
57
HorseIsleServer/LibHISP/Server/Start.cs
Normal file
57
HorseIsleServer/LibHISP/Server/Start.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using HISP.Game;
|
||||
using HISP.Game.Horse;
|
||||
using HISP.Game.Items;
|
||||
using HISP.Game.Services;
|
||||
using HISP.Game.SwfModules;
|
||||
using HISP.Security;
|
||||
using System;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
public static class Start
|
||||
{
|
||||
// "Entry Point"
|
||||
public static void InitalizeAndStart()
|
||||
{
|
||||
#if (!DEBUG)
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
||||
#endif
|
||||
|
||||
Console.Title = ServerVersion.GetBuildString();
|
||||
ConfigReader.OpenConfig();
|
||||
CrossDomainPolicy.GetPolicy();
|
||||
Database.OpenDatabase();
|
||||
GameDataJson.ReadGamedata();
|
||||
|
||||
Map.OpenMap();
|
||||
World.ReadWorldData();
|
||||
Treasure.Init();
|
||||
|
||||
DroppedItems.Init();
|
||||
WildHorse.Init();
|
||||
|
||||
Drawingroom.LoadAllDrawingRooms();
|
||||
Brickpoet.LoadPoetryRooms();
|
||||
Multiroom.CreateMultirooms();
|
||||
|
||||
Auction.LoadAllAuctionRooms();
|
||||
|
||||
Item.DoSpecialCases();
|
||||
|
||||
GameServer.StartServer();
|
||||
}
|
||||
|
||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
Exception execpt = (Exception)e.ExceptionObject;
|
||||
|
||||
Logger.ErrorPrint("HISP HAS CRASHED :(");
|
||||
Logger.ErrorPrint("Unhandled Exception: " + execpt.ToString());
|
||||
Logger.ErrorPrint(execpt.Message);
|
||||
Logger.ErrorPrint("");
|
||||
Logger.ErrorPrint(execpt.StackTrace);
|
||||
|
||||
while (true) { /* Allow asyncronous operations to happen. */ };
|
||||
}
|
||||
}
|
||||
}
|
54
HorseIsleServer/LibHISP/Server/Util.cs
Normal file
54
HorseIsleServer/LibHISP/Server/Util.cs
Normal file
|
@ -0,0 +1,54 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
public class Util
|
||||
{
|
||||
// Thanks Stackoverflow (https://stackoverflow.com/questions/321370/how-can-i-convert-a-hex-string-to-a-byte-array)
|
||||
private static int getHexVal(char hex)
|
||||
{
|
||||
int val = (int)hex;
|
||||
return val - (val < 58 ? 48 : (val < 97 ? 55 : 87));
|
||||
}
|
||||
public static byte[] StringToByteArray(string hex)
|
||||
{
|
||||
if (hex.Length % 2 == 1)
|
||||
throw new ArgumentException("The binary key cannot have an odd number of digits");
|
||||
|
||||
byte[] arr = new byte[hex.Length >> 1];
|
||||
|
||||
for (int i = 0; i < hex.Length >> 1; ++i)
|
||||
{
|
||||
arr[i] = (byte)((getHexVal(hex[i << 1]) << 4) + (getHexVal(hex[(i << 1) + 1])));
|
||||
}
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static double PointsToDistance(int x1, int y1, int x2, int y2)
|
||||
{
|
||||
return Math.Sqrt(Math.Pow((x2 - x1), 2) + Math.Pow((y2 - y1), 2));
|
||||
}
|
||||
public static string CapitalizeFirstLetter(string str)
|
||||
{
|
||||
char firstChar = char.ToUpper(str[0]);
|
||||
return firstChar + str.Substring(1);
|
||||
}
|
||||
public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
|
||||
{
|
||||
// Unix timestamp is seconds past epoch
|
||||
System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
||||
dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToUniversalTime();
|
||||
return dtDateTime;
|
||||
}
|
||||
|
||||
public static void ByteArrayToByteList(byte[] byteArray, List<byte> byteList)
|
||||
{
|
||||
byteList.AddRange(byteArray.ToList());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue