mirror of
https://github.com/islehorse/HISP.git
synced 2025-06-06 02:51:27 +12:00
Improve command system, add HELP command,
This commit is contained in:
parent
a2782fd35e
commit
9e69492e46
39 changed files with 1865 additions and 1620 deletions
|
@ -3545,8 +3545,6 @@ namespace HISP.Server
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void SetJewelrySlot1(int playerId, int itemId)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
|
@ -4145,7 +4143,24 @@ namespace HISP.Server
|
|||
}
|
||||
}
|
||||
|
||||
public static bool IsUserAdmin(int playerId)
|
||||
|
||||
public static bool GetUserModerator(int playerId)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
{
|
||||
db.Open();
|
||||
DbCommand sqlCommand = db.CreateCommand();
|
||||
|
||||
sqlCommand.CommandText = "SELECT Moderator FROM Users WHERE Id=@playerId";
|
||||
addWithValue(sqlCommand, "@playerId", playerId);
|
||||
sqlCommand.Prepare();
|
||||
bool admin = sqlCommand.ExecuteScalar().ToString() == "YES";
|
||||
|
||||
|
||||
return admin;
|
||||
}
|
||||
}
|
||||
public static bool GetUserAdmin(int playerId)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
{
|
||||
|
@ -4161,7 +4176,7 @@ namespace HISP.Server
|
|||
return admin;
|
||||
}
|
||||
}
|
||||
public static bool IsUserSubscribed(int playerId)
|
||||
public static bool GetUserSubscribed(int playerId)
|
||||
{
|
||||
if (ConfigReader.AllUsersSubbed)
|
||||
return true;
|
||||
|
@ -4456,6 +4471,38 @@ namespace HISP.Server
|
|||
|
||||
}
|
||||
}
|
||||
public static void SetUserMod(int playerId, bool moderator)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
{
|
||||
db.Open();
|
||||
DbCommand sqlCommand = db.CreateCommand();
|
||||
string yesno = (moderator ? "YES" : "NO");
|
||||
|
||||
sqlCommand.CommandText = "UPDATE Users SET Moderator=@moderator WHERE Id=@playerId";
|
||||
addWithValue(sqlCommand, "@playerId", playerId);
|
||||
addWithValue(sqlCommand, "@moderator", yesno);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetUserAdmin(int playerId, bool admin)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
{
|
||||
db.Open();
|
||||
DbCommand sqlCommand = db.CreateCommand();
|
||||
string yesno = (admin ? "YES" : "NO");
|
||||
|
||||
sqlCommand.CommandText = "UPDATE Users SET Admin=@admin WHERE Id=@playerId";
|
||||
addWithValue(sqlCommand, "@playerId", playerId);
|
||||
addWithValue(sqlCommand, "@admin", yesno);
|
||||
sqlCommand.Prepare();
|
||||
sqlCommand.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetNpcX(int npcId, int x)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
|
@ -4854,7 +4901,7 @@ namespace HISP.Server
|
|||
}
|
||||
|
||||
|
||||
public static bool CheckUserIsModerator(string username)
|
||||
public static bool CheckUsernameIsModerator(string username)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
{
|
||||
|
@ -4878,7 +4925,7 @@ namespace HISP.Server
|
|||
}
|
||||
|
||||
|
||||
public static bool CheckUserIsAdmin(string username)
|
||||
public static bool CheckUsernameIsAdmin(string username)
|
||||
{
|
||||
using (DbConnection db = connectDb())
|
||||
{
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace HISP.Server
|
|||
}
|
||||
}
|
||||
|
||||
private Transport networkTransport;
|
||||
private ITransport networkTransport;
|
||||
|
||||
private bool loggedIn = false;
|
||||
|
||||
|
@ -38,9 +38,9 @@ namespace HISP.Server
|
|||
get
|
||||
{
|
||||
bool login = loggedIn;
|
||||
if (LoggedinUser == null)
|
||||
if (User == null)
|
||||
return false;
|
||||
if (LoggedinUser.LoggedinClient == null)
|
||||
if (User.Client == null)
|
||||
return false;
|
||||
return login;
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ namespace HISP.Server
|
|||
loggedIn = value;
|
||||
}
|
||||
}
|
||||
public User LoggedinUser;
|
||||
public User User;
|
||||
|
||||
private Timer keepAliveTimer;
|
||||
private Timer timeoutTimer;
|
||||
|
@ -93,11 +93,11 @@ namespace HISP.Server
|
|||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
ItemInstance rubyItem = new ItemInstance(Item.Ruby);
|
||||
client.LoggedinUser.Inventory.AddIgnoringFull(rubyItem);
|
||||
client.User.Inventory.AddIgnoringFull(rubyItem);
|
||||
}
|
||||
|
||||
client.LoggedinUser.TrackedItems.GetTrackedItem(Tracking.TrackableItem.GameUpdates).Count++;
|
||||
Logger.DebugPrint("Kicking: " + client.LoggedinUser.Username);
|
||||
client.User.TrackedItems.GetTrackedItem(Tracking.TrackableItem.GameUpdates).Count++;
|
||||
Logger.DebugPrint("Kicking: " + client.User.Username);
|
||||
}
|
||||
client.Kick("Server shutdown: "+reason);
|
||||
}
|
||||
|
@ -169,7 +169,7 @@ namespace HISP.Server
|
|||
|
||||
private void keepAliveTick(object state)
|
||||
{
|
||||
Logger.DebugPrint("Sending keep-alive packet to " + LoggedinUser.Username);
|
||||
Logger.DebugPrint("Sending keep-alive packet to " + User.Username);
|
||||
byte[] updatePacket = PacketBuilder.CreateKeepAlive();
|
||||
SendPacket(updatePacket);
|
||||
keepAliveTimer.Change(oneMinute, oneMinute);
|
||||
|
@ -182,20 +182,20 @@ namespace HISP.Server
|
|||
|
||||
GameServer.UpdatePlayer(this);
|
||||
|
||||
LoggedinUser.CanUseAdsChat = true;
|
||||
LoggedinUser.FreeMinutes -= 1;
|
||||
User.CanUseAdsChat = true;
|
||||
User.FreeMinutes -= 1;
|
||||
|
||||
GameServer.DoItemPurchases(this);
|
||||
|
||||
if (totalMinutesElapsed % 2 == 0)
|
||||
{
|
||||
LoggedinUser.TotalGlobalChatMessages++;
|
||||
User.TotalGlobalChatMessages++;
|
||||
}
|
||||
|
||||
if (LoggedinUser.FreeMinutes <= 0)
|
||||
if (User.FreeMinutes <= 0)
|
||||
{
|
||||
LoggedinUser.FreeMinutes = 0;
|
||||
if (!LoggedinUser.Subscribed && !LoggedinUser.Moderator && !LoggedinUser.Administrator)
|
||||
User.FreeMinutes = 0;
|
||||
if (!User.Subscribed && !User.Moderator && !User.Administrator)
|
||||
{
|
||||
Kick(Messages.KickReasonNoTime);
|
||||
return;
|
||||
|
@ -214,11 +214,11 @@ namespace HISP.Server
|
|||
|
||||
if (GameServer.RandomNumberGenerator.Next(0, 100) == 59) // RANDOM EVENT HAS OCCURED!
|
||||
{
|
||||
RandomEvent.ExecuteRandomEvent(LoggedinUser);
|
||||
RandomEvent.ExecuteRandomEvent(User);
|
||||
}
|
||||
|
||||
bool gotoPrision = false;
|
||||
foreach(HorseInstance horse in LoggedinUser.HorseInventory.HorseList)
|
||||
foreach(HorseInstance horse in User.HorseInventory.HorseList)
|
||||
{
|
||||
if (totalMinutesElapsed % 2 == 0)
|
||||
{
|
||||
|
@ -290,28 +290,28 @@ namespace HISP.Server
|
|||
SendPacket(horseReturned);
|
||||
|
||||
if(tpX != 0 && tpY != 0)
|
||||
LoggedinUser.Teleport(tpX, tpY);
|
||||
User.Teleport(tpX, tpY);
|
||||
|
||||
|
||||
if (LoggedinUser.CurrentlyRidingHorse != null)
|
||||
if (User.CurrentlyRidingHorse != null)
|
||||
{
|
||||
if(LoggedinUser.CurrentlyRidingHorse.RandomId == horse.RandomId)
|
||||
if(User.CurrentlyRidingHorse.RandomId == horse.RandomId)
|
||||
{
|
||||
GameServer.StopRidingHorse(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(LoggedinUser.LastViewedHorse != null)
|
||||
if(User.LastViewedHorse != null)
|
||||
{
|
||||
if(LoggedinUser.LastViewedHorse.RandomId == horse.RandomId)
|
||||
if(User.LastViewedHorse.RandomId == horse.RandomId)
|
||||
{
|
||||
LoggedinUser.LastViewedHorse = null;
|
||||
User.LastViewedHorse = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
LoggedinUser.HorseInventory.DeleteHorse(horse);
|
||||
User.HorseInventory.DeleteHorse(horse);
|
||||
}
|
||||
|
||||
|
||||
|
@ -322,18 +322,18 @@ namespace HISP.Server
|
|||
{
|
||||
byte[] sendToPrision = PacketBuilder.CreateChat(Messages.YouWereSentToPrisionIsle, PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
SendPacket(sendToPrision);
|
||||
LoggedinUser.Teleport(45, 35);
|
||||
User.Teleport(45, 35);
|
||||
}
|
||||
|
||||
|
||||
if (totalMinutesElapsed % 5 == 0)
|
||||
LoggedinUser.Thirst--;
|
||||
User.Thirst--;
|
||||
|
||||
if (totalMinutesElapsed % 15 == 0)
|
||||
LoggedinUser.Hunger--;
|
||||
User.Hunger--;
|
||||
|
||||
if (totalMinutesElapsed % 15 == 0)
|
||||
LoggedinUser.Tiredness--;
|
||||
User.Tiredness--;
|
||||
}
|
||||
|
||||
minuteTimer.Change(oneMinute, oneMinute);
|
||||
|
@ -345,7 +345,7 @@ namespace HISP.Server
|
|||
byte[] chatPacket = PacketBuilder.CreateChat(Messages.FormatIdleWarningMessage(), PacketBuilder.CHAT_BOTTOM_RIGHT);
|
||||
SendPacket(chatPacket);
|
||||
if (LoggedIn)
|
||||
LoggedinUser.Idle = true;
|
||||
User.Idle = true;
|
||||
}
|
||||
|
||||
private void kickTimerTick(object state)
|
||||
|
@ -363,12 +363,12 @@ namespace HISP.Server
|
|||
{
|
||||
if (Client.LoggedIn)
|
||||
{
|
||||
if (Client.LoggedinUser.Id == id)
|
||||
if (Client.User.Id == id)
|
||||
Client.Kick(Messages.KickReasonDuplicateLogin);
|
||||
}
|
||||
}
|
||||
|
||||
LoggedinUser = new User(this, id);
|
||||
User = new User(this, id);
|
||||
LoggedIn = true;
|
||||
|
||||
Database.SetIpAddress(id, RemoteIp);
|
||||
|
@ -404,7 +404,7 @@ namespace HISP.Server
|
|||
if (keepAliveTimer != null && identifier != PacketBuilder.PACKET_KEEP_ALIVE)
|
||||
{
|
||||
if (LoggedIn)
|
||||
LoggedinUser.Idle = false;
|
||||
User.Idle = false;
|
||||
keepAliveTimer.Change(oneMinute, oneMinute);
|
||||
}
|
||||
else
|
||||
|
@ -547,7 +547,8 @@ namespace HISP.Server
|
|||
|
||||
public void SendPacket(byte[] packetData)
|
||||
{
|
||||
networkTransport.Send(packetData);
|
||||
if(!networkTransport.Disconnected)
|
||||
networkTransport.Send(packetData);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,9 +19,9 @@ namespace HISP.Server
|
|||
{
|
||||
public class GameDataJson
|
||||
{
|
||||
private static dynamic gameData;
|
||||
public static void ReadGamedata()
|
||||
{
|
||||
dynamic gameData;
|
||||
Logger.DebugPrint("Reading GAMEDATA");
|
||||
if (Directory.Exists(ConfigReader.GameData))
|
||||
{
|
||||
|
@ -158,10 +158,10 @@ namespace HISP.Server
|
|||
int totalReasons = gameData.messages.chat.reason_messages.Count;
|
||||
for (int i = 0; i < totalReasons; i++)
|
||||
{
|
||||
Chat.Reason reason = new Chat.Reason();
|
||||
ChatMsg.Reason reason = new ChatMsg.Reason();
|
||||
reason.Name = gameData.messages.chat.reason_messages[i].name;
|
||||
reason.Message = gameData.messages.chat.reason_messages[i].message;
|
||||
Chat.AddReason(reason);
|
||||
ChatMsg.AddReason(reason);
|
||||
|
||||
Logger.DebugPrint("Registered Chat Warning Reason: " + reason.Name + " (Message: " + reason.Message + ")");
|
||||
}
|
||||
|
@ -170,11 +170,11 @@ namespace HISP.Server
|
|||
int totalFilters = gameData.messages.chat.filter.Count;
|
||||
for (int i = 0; i < totalFilters; i++)
|
||||
{
|
||||
Chat.Filter filter = new Chat.Filter();
|
||||
ChatMsg.Filter filter = new ChatMsg.Filter();
|
||||
filter.FilteredWord = gameData.messages.chat.filter[i].word;
|
||||
filter.MatchAll = gameData.messages.chat.filter[i].match_all;
|
||||
filter.Reason = Chat.GetReason((string)gameData.messages.chat.filter[i].reason_type);
|
||||
Chat.AddFilter(filter);
|
||||
filter.Reason = ChatMsg.GetReason((string)gameData.messages.chat.filter[i].reason_type);
|
||||
ChatMsg.AddFilter(filter);
|
||||
|
||||
Logger.DebugPrint("Registered Filtered Word: " + filter.FilteredWord + " With reason: " + filter.Reason.Name + " (Matching all: " + filter.MatchAll + ")");
|
||||
}
|
||||
|
@ -183,10 +183,10 @@ namespace HISP.Server
|
|||
int totalCorrections = gameData.messages.chat.correct.Count;
|
||||
for (int i = 0; i < totalCorrections; i++)
|
||||
{
|
||||
Chat.Correction correction = new Chat.Correction();
|
||||
ChatMsg.Correction correction = new ChatMsg.Correction();
|
||||
correction.FilteredWord = gameData.messages.chat.correct[i].word;
|
||||
correction.ReplacedWord = gameData.messages.chat.correct[i].new_word;
|
||||
Chat.AddCorrection(correction);
|
||||
ChatMsg.AddCorrection(correction);
|
||||
|
||||
Logger.DebugPrint("Registered Word Correction: " + correction.FilteredWord + " to " + correction.ReplacedWord);
|
||||
}
|
||||
|
@ -468,10 +468,22 @@ namespace HISP.Server
|
|||
Logger.DebugPrint("Registered Abuse Report Reason: " + reason.Name);
|
||||
}
|
||||
|
||||
// Map Data
|
||||
/// Map Data
|
||||
|
||||
Map.OverlayTileDepth = gameData.tile_paramaters.overlay_tiles.tile_depth.ToObject<int[]>();
|
||||
// Overlay tile depth;
|
||||
List<Map.TileDepth> overlayTilesDepth = new List<Map.TileDepth>();
|
||||
int totalOverlayTileDepth = gameData.tile_paramaters.overlay_tiles.Count;
|
||||
for (int i = 0; i < totalOverlayTileDepth; i++)
|
||||
{
|
||||
Map.TileDepth tileDepth = new Map.TileDepth();
|
||||
tileDepth.Passable = gameData.tile_paramaters.overlay_tiles[i].passable;
|
||||
tileDepth.ShowPlayer = gameData.tile_paramaters.overlay_tiles[i].show_player;
|
||||
Logger.DebugPrint("Registered Overlay Tile: " + i + " Depth; Passable: " + tileDepth.Passable + " ShowPlayer: " + tileDepth.ShowPlayer);
|
||||
overlayTilesDepth.Add(tileDepth);
|
||||
}
|
||||
Map.OverlayTileDepth = overlayTilesDepth.ToArray();
|
||||
|
||||
// Terrain tile types and passable;
|
||||
List<Map.TerrainTile> terrainTiles = new List<Map.TerrainTile>();
|
||||
int totalTerrainTiles = gameData.tile_paramaters.terrain_tiles.Count;
|
||||
for (int i = 0; i < totalTerrainTiles; i++)
|
||||
|
@ -479,7 +491,7 @@ namespace HISP.Server
|
|||
Map.TerrainTile tile = new Map.TerrainTile();
|
||||
tile.Passable = gameData.tile_paramaters.terrain_tiles[i].passable;
|
||||
tile.Type = gameData.tile_paramaters.terrain_tiles[i].tile_type;
|
||||
Logger.DebugPrint("Registered Tile: " + i + " Passable: " + tile.Passable + " Type: " + tile.Type);
|
||||
Logger.DebugPrint("Registered Tile Information: " + i + " Passable: " + tile.Passable + " Type: " + tile.Type);
|
||||
terrainTiles.Add(tile);
|
||||
}
|
||||
Map.TerrainTiles = terrainTiles.ToArray();
|
||||
|
@ -939,7 +951,7 @@ namespace HISP.Server
|
|||
GameServer.IdleWarning = Convert.ToInt32(gameData.messages.disconnect.client_timeout.warn_after);
|
||||
GameServer.IdleTimeout = Convert.ToInt32(gameData.messages.disconnect.client_timeout.kick_after);
|
||||
|
||||
Chat.PrivateMessageSound = gameData.messages.chat.pm_sound;
|
||||
ChatMsg.PrivateMessageSound = gameData.messages.chat.pm_sound;
|
||||
|
||||
// New Users
|
||||
|
||||
|
@ -947,6 +959,9 @@ namespace HISP.Server
|
|||
Map.NewUserStartX = gameData.messages.new_user.starting_x;
|
||||
Map.NewUserStartY = gameData.messages.new_user.starting_y;
|
||||
|
||||
// HISP Specific ...
|
||||
Messages.HISPHelpCommandUsageFormat = gameData.hisp_specific.HISP_help_command_usage_format;
|
||||
|
||||
// Timed Messages
|
||||
|
||||
Messages.PlaytimeMessageFormat = gameData.messages.timed_messages.playtime_message;
|
||||
|
|
File diff suppressed because it is too large
Load diff
55
HorseIsleServer/LibHISP/Server/Network/NullSocket.cs
Normal file
55
HorseIsleServer/LibHISP/Server/Network/NullSocket.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
// A transport that does absolutely nothing.
|
||||
// only use this for testing.
|
||||
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace HISP.Server.Network
|
||||
{
|
||||
public class NullSocket : ITransport
|
||||
{
|
||||
private bool disconnected = false;
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "NullSocket";
|
||||
}
|
||||
}
|
||||
public bool Disconnected
|
||||
{
|
||||
get
|
||||
{
|
||||
return disconnected;
|
||||
}
|
||||
set
|
||||
{
|
||||
disconnected = value;
|
||||
}
|
||||
}
|
||||
|
||||
public string Ip
|
||||
{
|
||||
get
|
||||
{
|
||||
return IPAddress.Loopback.MapToIPv4().ToString();
|
||||
}
|
||||
}
|
||||
public void Accept(Socket socket, Action<byte[]> onReceive, Action onDisconnect)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public void Disconnect()
|
||||
{
|
||||
disconnected = true;
|
||||
return;
|
||||
}
|
||||
|
||||
public void Send(byte[] data)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,7 +6,6 @@ using System.Text;
|
|||
using HISP.Game;
|
||||
using HISP.Game.SwfModules;
|
||||
using HISP.Util;
|
||||
|
||||
namespace HISP.Server
|
||||
{
|
||||
public class PacketBuilder
|
||||
|
@ -14,6 +13,7 @@ namespace HISP.Server
|
|||
public const int PACKET_CLIENT_TERMINATOR_LENGTH = 1;
|
||||
public const byte PACKET_CLIENT_TERMINATOR = 0x0A;
|
||||
|
||||
// hi1 packets
|
||||
public const byte PACKET_LOGIN = 0x7F;
|
||||
public const byte PACKET_CHAT = 0x14;
|
||||
public const byte PACKET_MOVE = 0x15;
|
||||
|
@ -802,13 +802,28 @@ namespace HISP.Server
|
|||
// Creates a byte array of a packet informing the client of Tile Overlay flags
|
||||
// these tell the client what tiles are and are not passable, which ones the player
|
||||
// should appear ontop of or under, and stuff like that.
|
||||
public static byte[] CreateTileOverlayFlags(int[] tileDepthFlags)
|
||||
public static byte[] CreateTileOverlayFlags(Map.TileDepth[] tileDepthFlags)
|
||||
{
|
||||
byte[] packet = new byte[1 + tileDepthFlags.Length];
|
||||
packet[0] = PACKET_TILE_FLAGS;
|
||||
|
||||
for(int i = 0; i < tileDepthFlags.Length; i++)
|
||||
packet[1 + i] = (byte)(tileDepthFlags[i].ToString()[0]);
|
||||
{
|
||||
int flag;
|
||||
|
||||
if (!tileDepthFlags[i].ShowPlayer && !tileDepthFlags[i].Passable)
|
||||
flag = 0;
|
||||
else if (tileDepthFlags[i].ShowPlayer && !tileDepthFlags[i].Passable)
|
||||
flag = 1;
|
||||
else if (!tileDepthFlags[i].ShowPlayer && tileDepthFlags[i].Passable)
|
||||
flag = 2;
|
||||
else if (tileDepthFlags[i].ShowPlayer && tileDepthFlags[i].Passable)
|
||||
flag = 3;
|
||||
else
|
||||
throw new Exception("Somehow, showplayers was not true or false, and passable was not true or false, this should be impossible");
|
||||
|
||||
packet[1 + i] = Convert.ToByte(flag.ToString()[0]);
|
||||
}
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue