Use Async Io instead of threads

This commit is contained in:
Bluzume 2021-10-27 01:32:29 -04:00
parent 392a3dfcaa
commit edb27809bd
17 changed files with 128 additions and 104 deletions

View file

@ -304,7 +304,7 @@ namespace HISP.Game.Chat
if (channel == ChatChannel.All)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MuteGlobal && !client.LoggedinUser.MuteAll)
@ -318,7 +318,7 @@ namespace HISP.Game.Chat
if(channel == ChatChannel.Ads)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MuteAds && !client.LoggedinUser.MuteAll)
@ -332,7 +332,7 @@ namespace HISP.Game.Chat
if(channel == ChatChannel.Buddies)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MuteBuddy && !client.LoggedinUser.MuteAll)
@ -403,7 +403,7 @@ namespace HISP.Game.Chat
}
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Moderator)
@ -423,7 +423,7 @@ namespace HISP.Game.Chat
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Administrator)
@ -438,7 +438,7 @@ namespace HISP.Game.Chat
if (to != null)
{
List<GameClient> recipiants = new List<GameClient>();
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MutePrivateMessage && !client.LoggedinUser.MuteAll)

View file

@ -13,7 +13,7 @@ namespace HISP.Game.Chat
private static User findNamePartial(string name)
{
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client == null)
continue;

View file

@ -18,7 +18,7 @@ namespace HISP.Game.Events
tradingTimeout = new Timer(new TimerCallback(tradeTimedOut), null, TRADING_TIMEOUT * 60 * 1000, TRADING_TIMEOUT * 60 * 1000);
byte[] msg = PacketBuilder.CreateChat(Messages.EventStartIsleTradingGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(msg);
@ -46,7 +46,7 @@ namespace HISP.Game.Events
{
Active = false;
foreach(GameClient client in GameServer.ConnectedClients)
foreach(GameClient client in GameClient.ConnectedClients)
{
if(client.LoggedIn)
{

View file

@ -72,7 +72,7 @@ namespace HISP.Game.Events
byte[] annoucePacket = PacketBuilder.CreateChat(Messages.EventStartModsRevenge, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(annoucePacket);
}
@ -83,7 +83,7 @@ namespace HISP.Game.Events
byte[] annoucePacket = PacketBuilder.CreateChat(Messages.EventEndModsRevenge, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(annoucePacket);
}

View file

@ -169,7 +169,7 @@ namespace HISP.Game.Events
quizTimer = new Timer(new TimerCallback(quizTimesUp), null, QUIZ_TIMEOUT * 60 * 1000, QUIZ_TIMEOUT * 60 * 1000);
byte[] quizStartMessage = PacketBuilder.CreateChat(Messages.EventStartRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(quizStartMessage);
@ -181,7 +181,7 @@ namespace HISP.Game.Events
public void WinEvent(User winner)
{
byte[] eventWinMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeQuizWin(winner.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(eventWinMessage);
@ -199,7 +199,7 @@ namespace HISP.Game.Events
public void EndEvent()
{
byte[] eventEndMessage = PacketBuilder.CreateChat(Messages.EventEndRealTimeQuiz, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if(client.LoggedIn)
client.SendPacket(eventEndMessage);

View file

@ -37,7 +37,7 @@ namespace HISP.Game.Events
riddleTimeout = new Timer(new TimerCallback(riddleTimedOut), null, RIDDLE_TIMEOUT * 60 * 1000, RIDDLE_TIMEOUT * 60 * 1000);
// Send riddle message to all players
foreach(GameClient client in GameServer.ConnectedClients)
foreach(GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
ShowStartMessage(client);
@ -74,7 +74,7 @@ namespace HISP.Game.Events
winner.AddMoney(Reward);
byte[] riddleWonMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeRiddleWonForOthers(winner.Username), PacketBuilder.CHAT_BOTTOM_RIGHT);
byte[] riddleYouWonMessage = PacketBuilder.CreateChat(Messages.FormatEventRealTimeRiddleWonForYou(Reward), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Id != winner.Id)
@ -95,7 +95,7 @@ namespace HISP.Game.Events
private void riddleTimedOut(object state)
{
byte[] riddleTimedOutMessage = PacketBuilder.CreateChat(Messages.EventEndRealTimeRiddle, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
client.SendPacket(riddleTimedOutMessage);

View file

@ -32,7 +32,7 @@ namespace HISP.Game.Events
if (timesTicked >= 1)
{
byte[] giveAwayMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveaway1Min(HorseGiveaway.Color, HorseGiveaway.Breed.Name, HorseGiveaway.Gender, ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(giveAwayMessage);
}
@ -105,7 +105,7 @@ namespace HISP.Game.Events
giveAwayTimer = new Timer(new TimerCallback(giveawayTick), null, TACKSHOP_TIMEOUT * 60 * 1000, TACKSHOP_TIMEOUT * 60 * 1000);
byte[] giveAwayMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayStart(HorseGiveaway.Color, HorseGiveaway.Breed.Name, HorseGiveaway.Gender, ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(giveAwayMessage);
@ -132,7 +132,7 @@ namespace HISP.Game.Events
winner.TrackedItems.GetTrackedItem(Tracking.TrackableItem.TackShopGiveaway).Count++;
byte[] horseWonMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayWon(winner.Username, HorseGiveaway.Breed.Name, ShopName, Town.Name, usersHere.Length), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(horseWonMessage);
@ -140,7 +140,7 @@ namespace HISP.Game.Events
else
{
byte[] eventEndedMessage = PacketBuilder.CreateChat(Messages.FormatEventTackShopGiveawayEnd(ShopName, Town.Name), PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(eventEndedMessage);
}

View file

@ -48,7 +48,7 @@ namespace HISP.Game.Events
gameTimeout = new Timer(new TimerCallback(gameTimedOut), null, WATER_BALLOON_GAME_TIMEOUT * 60 * 1000, WATER_BALLOON_GAME_TIMEOUT * 60 * 1000);
byte[] gameStartMessage = PacketBuilder.CreateChat(Messages.EventStartWaterBallonGame, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(gameStartMessage);
@ -71,7 +71,7 @@ namespace HISP.Game.Events
// Send to all online users
byte[] gameWinnerAnnoucement = PacketBuilder.CreateChat(winMsg, PacketBuilder.CHAT_BOTTOM_RIGHT);
foreach (GameClient client in GameServer.ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
client.SendPacket(gameWinnerAnnoucement);

View file

@ -1165,7 +1165,7 @@ namespace HISP.Game
public static string BuildPlayerListAlphabetical(User currentUser)
{
string message = Messages.PlayerListAllAlphabeticalHeader;
GameClient[] clients = GameServer.ConnectedClients;
GameClient[] clients = GameClient.ConnectedClients;
List<User> onlineUsers = new List<User>();
foreach (GameClient client in clients)
@ -1202,7 +1202,7 @@ namespace HISP.Game
public static string BuildPlayerList(User currentUser)
{
string message = Messages.PlayerListAllHeader;
GameClient[] clients = GameServer.ConnectedClients;
GameClient[] clients = GameClient.ConnectedClients;
foreach (GameClient client in clients)
{
if (client.LoggedIn)

View file

@ -18,7 +18,7 @@ namespace HISP
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
#endif
Console.Title = "HISP - HorseIsleServer Emulator";
Console.Title = ServerVersion.GetVersionString();
ConfigReader.OpenConfig();
CrossDomainPolicy.GetPolicy();
Database.OpenDatabase();
@ -41,6 +41,7 @@ namespace HISP
GameServer.StartServer();
while (true) { };
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)

View file

@ -1,5 +1,4 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@ -10,7 +9,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("SilicaAndPina")]
[assembly: AssemblyProduct("HISP")]
[assembly: AssemblyCopyright("Public Domain © 2021")]
[assembly: AssemblyCopyright("Public Domain © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@ -32,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]

View file

@ -1 +1 @@
2d7ceb8b12b72d2b16189c41b099488d8ca15f6a
392a3dfcaaaca0e4f3aba9b428d07830550dbd78

View file

@ -21,7 +21,17 @@ namespace HISP.Server
ConnectionString = "server=" + ConfigReader.DatabaseIP + ";user=" + ConfigReader.DatabaseUsername + ";password=" + ConfigReader.DatabasePassword + ";database=" + ConfigReader.DatabaseName;
using (MySqlConnection db = new MySqlConnection(ConnectionString))
{
db.Open();
try
{
db.Open();
}
catch (MySqlException e)
{
Logger.ErrorPrint("Failed to connect to Database: "+e.Message);
Environment.Exit(1);
}
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))";

View file

@ -3,6 +3,7 @@ using System.IO;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Collections.Generic;
using HISP.Player;
using HISP.Game;
using HISP.Game.Horse;
@ -12,6 +13,15 @@ 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;
@ -33,8 +43,6 @@ namespace HISP.Server
}
}
public User LoggedinUser;
private Thread recvPackets;
private Timer inactivityTimer;
@ -233,8 +241,11 @@ namespace HISP.Server
SendPacket(chatPacket);
if (LoggedIn)
LoggedinUser.Idle = true;
warnTimer.Dispose();
warnTimer = null;
if(warnTimer != null)
{
warnTimer.Dispose();
warnTimer = null;
}
}
@ -246,7 +257,7 @@ namespace HISP.Server
public void Login(int id)
{
// Check for duplicate
foreach(GameClient Client in GameServer.ConnectedClients)
foreach(GameClient Client in GameClient.ConnectedClients)
{
if(Client.LoggedIn)
{
@ -317,16 +328,17 @@ namespace HISP.Server
warnTimer.Dispose();
if(kickTimer != null)
kickTimer.Dispose();
// Call OnDisconnect
connectedClients.Remove(this);
GameServer.OnDisconnect(this);
LoggedIn = false;
// LoggedinUser = null;
// Close Sockets
// Close Socket
ClientSocket.Close();
ClientSocket.Dispose();
return isDisconnecting; // Stop the thread.
return isDisconnecting; // Stop the task.
}
private void parsePackets(byte[] Packet)
@ -492,12 +504,25 @@ namespace HISP.Server
warnTimer = new Timer(new TimerCallback(warnTimerTick), null, warnInterval, warnInterval);
minuteTimer = new Timer(new TimerCallback(minuteTimerTick), null, oneMinute, oneMinute);
recvPackets = new Thread(() =>
{
receivePackets();
});
recvPackets.Start();
connectedClients.Add(this);
receivePackets();
}
public static void AcceptConnections(SocketAsyncEventArgs e, Socket socket)
{
e.AcceptSocket = null;
socket.AcceptAsync(e);
}
public static void CreateClient(object sender, SocketAsyncEventArgs e)
{
Socket eSocket = e.AcceptSocket;
AcceptConnections(e, GameServer.ServerSocket);
GameClient client = new GameClient(eSocket);
}
}
}

View file

@ -26,13 +26,6 @@ namespace HISP.Server
public static Socket ServerSocket;
public static GameClient[] ConnectedClients // Done to prevent Enumerator Changed errors.
{
get {
return connectedClients.ToArray();
}
}
public static int IdleTimeout;
public static int IdleWarning;
@ -52,7 +45,6 @@ namespace HISP.Server
private static int gameTickSpeed = 480; // Changing this to ANYTHING else will cause desync with the client.
private static int totalMinutesElapsed = 0;
private static int oneMinute = 1000 * 60;
private static List<GameClient> connectedClients = new List<GameClient>();
private static Timer gameTimer; // Controls in-game time.
private static Timer minuteTimer; // ticks every real world minute.
private static int lastServerTime = 0;
@ -193,7 +185,7 @@ namespace HISP.Server
}
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client == null)
continue;
@ -3629,7 +3621,7 @@ namespace HISP.Server
UpdateArea(sender);
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
@ -3690,7 +3682,7 @@ namespace HISP.Server
// Send login message
byte[] loginMessageBytes = PacketBuilder.CreateChat(Messages.FormatLoginMessage(sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_LEFT);
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
if (!client.LoggedinUser.MuteLogins && !client.LoggedinUser.MuteAll)
if (client.LoggedinUser.Id != sender.LoggedinUser.Id)
@ -3702,7 +3694,7 @@ namespace HISP.Server
byte[] yourPlayerInfo = PacketBuilder.CreatePlayerInfoUpdateOrCreate(sender.LoggedinUser.X, sender.LoggedinUser.Y, sender.LoggedinUser.Facing, sender.LoggedinUser.CharacterId, sender.LoggedinUser.Username);
byte[] yourPlayerInfoOffscreen = PacketBuilder.CreatePlayerInfoUpdateOrCreate(1000 + 4, 1000 + 1, sender.LoggedinUser.Facing, sender.LoggedinUser.CharacterId, sender.LoggedinUser.Username);
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
@ -5687,7 +5679,6 @@ namespace HISP.Server
Chat.ChatChannel channel = (Chat.ChatChannel)packet[1];
string message = packetStr.Substring(2, packetStr.Length - 4);
Logger.DebugPrint(sender.LoggedinUser.Username + " Attempting to say '" + message + "' in channel: " + channel.ToString());
string nameTo = null;
@ -5697,14 +5688,11 @@ namespace HISP.Server
message = Chat.GetDmMessage(message);
}
if (message == "")
return;
if(message.StartsWith("/"))
if (message.StartsWith("/"))
{
string channelString = message.Split(' ')[0].ToLower();
string newMessage = string.Join(' ', message.Split(' ').Skip(1));
message = newMessage;
message = newMessage.Trim();
switch(channelString)
{
case "/$":
@ -5748,11 +5736,20 @@ namespace HISP.Server
nameTo = channelString.Substring(1);
break;
}
if (message == "") // this is how pinto does it, im serious.
{
channel = Chat.ChatChannel.Dm;
nameTo = channelString.Substring(1);
}
}
message = message.Trim();
if(channel == Chat.ChatChannel.All && message.Length > 150)
if (message == "")
return;
if (channel == Chat.ChatChannel.All && message.Length > 150)
{
byte[] tooLong = PacketBuilder.CreateChat(Messages.GlobalChatTooLong, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(tooLong);
@ -6573,7 +6570,7 @@ namespace HISP.Server
}
catch (FormatException)
{
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent an invalid object interaction packet.");
Logger.ErrorPrint(sender.LoggedinUser.Username + " Sent an invalid object interaction packet. (drop)");
return;
}
@ -6592,6 +6589,8 @@ namespace HISP.Server
byte[] chatPacket = PacketBuilder.CreateChat(Messages.DroppedAnItemMessage, PacketBuilder.CHAT_BOTTOM_RIGHT);
sender.SendPacket(chatPacket);
UpdateInventory(sender);
UpdateAreaForAll(sender.LoggedinUser.X, sender.LoggedinUser.Y, false, sender.LoggedinUser);
}
else
{
@ -7283,10 +7282,6 @@ namespace HISP.Server
public static void OnDisconnect(GameClient sender)
{
connectedClients.Remove(sender);
if (sender.LoggedIn)
{
Database.SetPlayerLastLogin(Convert.ToInt32(new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds()), sender.LoggedinUser.Id); // Set last login date
@ -7321,7 +7316,7 @@ namespace HISP.Server
// Send disconnect message
byte[] logoutMessageBytes = PacketBuilder.CreateChat(Messages.FormatLogoutMessage(sender.LoggedinUser.Username), PacketBuilder.CHAT_BOTTOM_LEFT);
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
if (!client.LoggedinUser.MuteLogins && !client.LoggedinUser.MuteAll)
if (client.LoggedinUser.Id != sender.LoggedinUser.Id)
@ -7329,13 +7324,12 @@ namespace HISP.Server
// Tell clients of diconnect (remove from chat)
byte[] playerRemovePacket = PacketBuilder.CreatePlayerLeavePacket(sender.LoggedinUser.Username);
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
if (client.LoggedinUser.Id != sender.LoggedinUser.Id)
client.SendPacket(playerRemovePacket);
}
}
/*
@ -7359,7 +7353,7 @@ namespace HISP.Server
public static User[] GetUsersInTown(World.Town town, bool includeStealth = false, bool includeMuted = false)
{
List<User> usersInTown = new List<User>();
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
{
if (!includeStealth && client.LoggedinUser.Stealth)
@ -7376,7 +7370,7 @@ namespace HISP.Server
public static User[] GetUsersInIsle(World.Isle isle, bool includeStealth = false, bool includeMuted = false)
{
List<User> usersInIsle = new List<User>();
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
{
if (!includeStealth && client.LoggedinUser.Stealth)
@ -7395,7 +7389,7 @@ namespace HISP.Server
{
List<User> userList = new List<User>();
foreach (GameClient client in connectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
@ -7416,7 +7410,7 @@ namespace HISP.Server
public static User[] GetUsersAt(int x, int y, bool includeStealth = false, bool includeMuted = false)
{
List<User> usersHere = new List<User>();
foreach(GameClient client in ConnectedClients)
foreach(GameClient client in GameClient.ConnectedClients)
{
if(client.LoggedIn)
{
@ -7432,7 +7426,7 @@ namespace HISP.Server
}
public static User GetUserByName(string username)
{
foreach(GameClient client in ConnectedClients)
foreach(GameClient client in GameClient.ConnectedClients)
{
if(client.LoggedIn)
{
@ -7445,7 +7439,7 @@ namespace HISP.Server
public static User GetUserById(int id)
{
foreach(GameClient client in ConnectedClients)
foreach(GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Id == id)
@ -7463,7 +7457,7 @@ namespace HISP.Server
int endY = y + 3;
List<User> usersNearby = new List<User>();
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
{
if (startX <= client.LoggedinUser.X && endX >= client.LoggedinUser.X && startY <= client.LoggedinUser.Y && endY >= client.LoggedinUser.Y)
@ -7490,7 +7484,7 @@ namespace HISP.Server
List<User> usersOnScreen = new List<User>();
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
{
if (!includeStealth && client.LoggedinUser.Stealth)
@ -7512,7 +7506,7 @@ namespace HISP.Server
int endY = y + 19;
List<User> usersNearby = new List<User>();
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
{
if (!includeStealth && client.LoggedinUser.Stealth)
@ -7528,7 +7522,7 @@ namespace HISP.Server
public static int GetNumberOfPlayers(bool includeStealth=false)
{
int count = 0;
foreach(GameClient client in ConnectedClients)
foreach(GameClient client in GameClient.ConnectedClients)
if (client.LoggedIn)
{
if (!includeStealth && client.LoggedinUser.Stealth)
@ -7544,7 +7538,7 @@ namespace HISP.Server
{
List<Point> allLocations = new List<Point>();
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
@ -7566,7 +7560,7 @@ namespace HISP.Server
{
List<Point> allLocations = new List<Point>();
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
{
@ -7586,7 +7580,7 @@ namespace HISP.Server
public static int GetNumberOfPlayersListeningToAdsChat()
{
int count = 0;
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (!client.LoggedinUser.MuteAds)
@ -7598,7 +7592,7 @@ namespace HISP.Server
public static int GetNumberOfModsOnline()
{
int count = 0;
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if(client.LoggedinUser.Moderator)
@ -7623,7 +7617,7 @@ namespace HISP.Server
public static int GetNumberOfAdminsOnline()
{
int count = 0;
foreach (GameClient client in ConnectedClients)
foreach (GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.Administrator)
@ -7740,7 +7734,7 @@ namespace HISP.Server
}
public static void UpdateAreaForAll(int x, int y, bool ignoreMetaPrio=false, User exceptMe=null)
{
foreach(GameClient client in ConnectedClients)
foreach(GameClient client in GameClient.ConnectedClients)
{
if (client.LoggedIn)
if (client.LoggedinUser.X == x && client.LoggedinUser.Y == y)
@ -7856,7 +7850,7 @@ namespace HISP.Server
public static void RemoveAllItemsOfIdInTheGame(int id)
{
// Remove from all online players
foreach (GameClient connectedClient in GameServer.ConnectedClients)
foreach (GameClient connectedClient in GameClient.ConnectedClients)
{
if (connectedClient.LoggedIn)
if (connectedClient.LoggedinUser.Inventory.HasItemId(id))
@ -8042,22 +8036,15 @@ namespace HISP.Server
IPAddress hostIP = IPAddress.Parse(ConfigReader.BindIP);
IPEndPoint ep = new IPEndPoint(hostIP, ConfigReader.Port);
ServerSocket.Bind(ep);
Logger.InfoPrint("Binding to ip: " + ConfigReader.BindIP + " On port: " + ConfigReader.Port.ToString());
ServerSocket.Listen(10000);
ServerSocket.Listen(0x7fffffff);
gameTimer = new Timer(new TimerCallback(onGameTick), null, gameTickSpeed, gameTickSpeed);
minuteTimer = new Timer(new TimerCallback(onMinuteTick), null, oneMinute, oneMinute);
while (true)
{
Logger.InfoPrint("Waiting for new connections...");
Logger.InfoPrint("Binding to ip: " + ConfigReader.BindIP + " On port: " + ConfigReader.Port.ToString());
Socket cientSocket = ServerSocket.Accept();
GameClient client = new GameClient(cientSocket);
connectedClients.Add(client);
}
SocketAsyncEventArgs e = new SocketAsyncEventArgs();
e.Completed += GameClient.CreateClient;
GameClient.AcceptConnections(e, ServerSocket);
}
}
}

View file

@ -340,10 +340,12 @@ namespace HISP.Server
public static byte[] CreateDrawingUpdatePacket(string Drawing)
{
MemoryStream ms = new MemoryStream();
ms.WriteByte(PACKET_SWFMODULE);
byte[] drawingBytes = Encoding.UTF8.GetBytes(Drawing);
ms.Write(drawingBytes, 0x00, drawingBytes.Length);
ms.WriteByte(PACKET_TERMINATOR);
ms.Seek(0x00, SeekOrigin.Begin);
return ms.ToArray();
}

View file

@ -45,7 +45,7 @@ namespace HISP.Server
}
public static string GetCommitHash(int TotalBytes)
{
return Resources.GitCommit.Substring(0, TotalBytes * 2);
return Resources.GitCommit.Substring(0, TotalBytes);
}
public static string GetBuildString()
{