static void Main(string[] args) { Console.Title = "HISP - Horse Isle Server Emulator"; 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(); }
static void Main(string[] args) { #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(); while (true) { } ; }
private void ReceiveDataCallback(IAsyncResult ar) { if (ClientSocket == null || !ClientSocket.Connected || Disposing) { return; } try { var bytesReceived = ClientSocket.EndReceive(ar); if (bytesReceived == 0) { Logger.Info($"[{Username ?? "Anonymous"}] has disconnected from the server."); if (Username != null) { PlayerRoom.RemovePlayer(Username); } Disconnect(); return; } var packetBytes = new byte[bytesReceived]; Buffer.BlockCopy(SocketBuffer, 0, packetBytes, 0, bytesReceived); try { var packetString = Encoding.Default.GetString(packetBytes); var packetXml = XElement.Parse(packetString.Substring(0, packetString.Length - 1)); // TODO: Make sure entire packet is here /0 if (packetXml.Name.LocalName.Equals("policy-file-request")) { Logger.Debug("Received policy request"); ClientSocket.Send(Encoding.Default.GetBytes(CrossDomainPolicy.GetPolicy())); } else { PacketHandler.HandleIncomingMessage(new IncomingMessage(packetXml), this); } } catch (XmlException) { // ignored } } catch (Exception exception) { Logger.Error(exception, "Client generated an exception."); } finally { ReceiveData(); } }
private void ReceiveDataCallback(IAsyncResult ar) { if (ClientSocket == null || !ClientSocket.Connected || Disposing) { return; } try { var bytesReceived = ClientSocket.EndReceive(ar); if (bytesReceived == 0) { Logger.Info($"[{Username ?? "Anonymous"}] has disconnected from the server."); if (Username != null) { PlayerRoom.RemovePlayer(Username); } Disconnect(); return; } var packetBytes = new byte[bytesReceived]; Buffer.BlockCopy(SocketBuffer, 0, packetBytes, 0, bytesReceived); var packetString = Encoding.ASCII.GetString(packetBytes); packetString = packetString.Substring(0, packetString.Length - 1); // TODO: Make sure entire packet is here /0 packetString = Constants.PacketFix.Replace(packetString, match => // Fix packet starting with numbers { var replacement = Constants.PacketFixMap[match.Groups["number"].Value]; return($"<{replacement} "); }); try { var packetXml = XElement.Parse(packetString); if (packetXml.Name.LocalName.Equals("policy-file-request")) { Logger.Debug("Received policy request"); ClientSocket.Send(Encoding.ASCII.GetBytes(CrossDomainPolicy.GetPolicy())); } else { PacketHandler.HandleIncomingMessage(new IncomingMessage(packetXml), this); } } catch (XmlException exception) { Logger.Error(exception, $"[{Username ?? "Anonymous"}] Invalid xml was received: '{packetString}'."); } } catch (Exception exception) { Logger.Error(exception, $"[{Username ?? "Anonymous"}] Client generated an exception."); } finally { ReceiveData(); } }