mirror of
https://github.com/islehorse/HISP.git
synced 2025-05-23 19:46:26 +12:00
Add Feature pt2
This commit is contained in:
parent
092534e331
commit
67275262fb
36 changed files with 1555 additions and 296 deletions
HorseIsleServer/LibHISP/Server
|
@ -1,5 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.Common;
|
||||
|
||||
using HISP.Game;
|
||||
using HISP.Player;
|
||||
using HISP.Game.Horse;
|
||||
|
@ -11,7 +13,6 @@ using HISP.Game.SwfModules;
|
|||
|
||||
using MySqlConnector;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using System.Data.Common;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
|
@ -39,12 +40,18 @@ namespace HISP.Server
|
|||
return new SqliteConnection(ConnectionString);
|
||||
}
|
||||
|
||||
public static void OnShutdown()
|
||||
{
|
||||
MySqlConnection.ClearAllPools();
|
||||
SqliteConnection.ClearAllPools();
|
||||
}
|
||||
|
||||
public static void OpenDatabase()
|
||||
{
|
||||
if (!ConfigReader.SqlLite)
|
||||
ConnectionString = "server=" + ConfigReader.DatabaseIP + ";user=" + ConfigReader.DatabaseUsername + ";password=" + ConfigReader.DatabasePassword + ";database=" + ConfigReader.DatabaseName;
|
||||
ConnectionString = "server=" + ConfigReader.DatabaseIP + ";user=" + ConfigReader.DatabaseUsername + ";password=" + ConfigReader.DatabasePassword + ";database=" + ConfigReader.DatabaseName;
|
||||
else
|
||||
ConnectionString = "Data Source=./" + ConfigReader.DatabaseName + ".db;";
|
||||
ConnectionString = "Data Source=./" + ConfigReader.DatabaseName + ".db;";
|
||||
|
||||
Logger.InfoPrint(ConnectionString);
|
||||
|
||||
|
@ -61,6 +68,8 @@ namespace HISP.Server
|
|||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
string SqlPragma = "PRAGMA journal_mode=WAL;";
|
||||
|
||||
string UserTable = "CREATE TABLE IF NOT EXISTS Users(Id INT, Username TEXT(16), PassHash TEXT(128), Salt TEXT(128), Gender TEXT(16), Admin TEXT(3), Moderator TEXT(3))";
|
||||
string ExtTable = "CREATE TABLE IF NOT EXISTS UserExt(Id INT, X INT, Y INT, LastLogin INT, Money INT, QuestPoints INT, BankBalance DOUBLE, BankInterest DOUBLE, ProfilePage Text(4000),IpAddress TEXT(1028),PrivateNotes Text(65535), CharId INT, ChatViolations INT,Subscriber TEXT(3), SubscribedUntil INT, Experience INT, Tiredness INT, Hunger INT, Thirst INT, FreeMinutes INT, TotalLogins INT)";
|
||||
string MailTable = "CREATE TABLE IF NOT EXISTS Mailbox(RandomId INT, IdTo INT, IdFrom INT, Subject TEXT(100), Message Text(65535), TimeSent INT, BeenRead TEXT(3))";
|
||||
|
@ -99,6 +108,20 @@ namespace HISP.Server
|
|||
string DeleteOnlineUsers = "DROP TABLE OnlineUsers";
|
||||
string OnlineUsers = "CREATE TABLE IF NOT EXISTS OnlineUsers(playerId INT, Admin TEXT(3), Moderator TEXT(3), Subscribed TEXT(3), New TEXT(3))";
|
||||
|
||||
if (ConfigReader.SqlLite)
|
||||
{
|
||||
try
|
||||
{
|
||||
DbCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = SqlPragma;
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.WarnPrint(e.Message);
|
||||
};
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
DbCommand sqlCommand = db.CreateCommand();
|
||||
|
@ -4675,7 +4698,6 @@ namespace HISP.Server
|
|||
|
||||
Int32 count = Convert.ToInt32(sqlCommand.ExecuteScalar());
|
||||
|
||||
|
||||
return count >= 1;
|
||||
}
|
||||
}
|
||||
|
@ -4874,6 +4896,23 @@ namespace HISP.Server
|
|||
}
|
||||
}
|
||||
|
||||
public static int GetNextFreeUserId()
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
{
|
||||
db.Open();
|
||||
DbCommand sqlCommand = db.CreateCommand();
|
||||
sqlCommand.CommandText = "SELECT MAX(Id)+1 FROM Users";
|
||||
sqlCommand.Prepare();
|
||||
|
||||
object res = sqlCommand.ExecuteScalar();
|
||||
if (res == DBNull.Value)
|
||||
return 0;
|
||||
|
||||
return Convert.ToInt32(res);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CreateUser(int id, string username, string passhash, string salt, string gender, bool admin, bool moderator)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
|
|
|
@ -5,13 +5,28 @@ using HISP.Game.Services;
|
|||
using HISP.Game.SwfModules;
|
||||
using HISP.Security;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
public static class Start
|
||||
public static class Entry
|
||||
{
|
||||
// "Entry Point"
|
||||
public static void InitalizeAndStart()
|
||||
|
||||
|
||||
private static void defaultOnShutdownCallback()
|
||||
{
|
||||
Process.GetCurrentProcess().Close();
|
||||
}
|
||||
public static Action OnShutdown = defaultOnShutdownCallback;
|
||||
|
||||
|
||||
public static void SetShutdownCallback(Action callback)
|
||||
{
|
||||
OnShutdown = callback;
|
||||
}
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
#if (!DEBUG)
|
||||
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
|
|
@ -1,12 +1,13 @@
|
|||
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;
|
||||
using HISP.Game.Items;
|
||||
using HISP.Game.Inventory;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
|
@ -87,6 +88,30 @@ namespace HISP.Server
|
|||
receivePackets(null, evt);
|
||||
}
|
||||
|
||||
public static void OnShutdown()
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (GameClient client in ConnectedClients)
|
||||
{
|
||||
|
||||
if (client.LoggedIn)
|
||||
{
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
ItemInstance rubyItem = new ItemInstance(Item.Ruby);
|
||||
client.LoggedinUser.Inventory.AddIgnoringFull(rubyItem);
|
||||
}
|
||||
|
||||
client.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.GameUpdates).Count++;
|
||||
}
|
||||
|
||||
client.Kick("Server shutdown.");
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception) { };
|
||||
}
|
||||
public static void CreateClient(object sender, SocketAsyncEventArgs e)
|
||||
{
|
||||
do
|
||||
|
@ -114,7 +139,7 @@ namespace HISP.Server
|
|||
// Close Socket
|
||||
if (ClientSocket != null)
|
||||
{
|
||||
ClientSocket.Close();
|
||||
ClientSocket.Disconnect(false);
|
||||
ClientSocket.Dispose();
|
||||
ClientSocket = null;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ using HISP.Game.SwfModules;
|
|||
using HISP.Game.Horse;
|
||||
using HISP.Game.Events;
|
||||
using HISP.Game.Items;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
|
@ -8251,6 +8252,20 @@ namespace HISP.Server
|
|||
}
|
||||
return true;
|
||||
}
|
||||
public static void OnShutdown()
|
||||
{
|
||||
ServerSocket.Dispose();
|
||||
gameTimer.Dispose();
|
||||
minuteTimer.Dispose();
|
||||
}
|
||||
public static void ShutdownServer()
|
||||
{
|
||||
GameClient.OnShutdown();
|
||||
GameServer.OnShutdown();
|
||||
Database.OnShutdown();
|
||||
Entry.OnShutdown();
|
||||
}
|
||||
|
||||
public static void StartServer()
|
||||
{
|
||||
ServerSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue