public static void InitializeServer() { var startTime = GetTickCount(); Cnsl.Info("Initializing Server", true); //Intializing all game data arrays Cnsl.Debug("Initializing Game Arrays", true); for (var i = 0; i < Constants.MAX_PLAYERS; i++) { ServerTcp.Client[i] = new Clients(); } Cnsl.Finalize("Initializing Game Arrays"); //Start the Networking Cnsl.Debug("Initializing Network", true); Cnsl.Debug("Initializing Status Listener", true); ServerHandleData.InitializePackets(); ServerTcp.InitializeNetwork(); ServerTcp.InitializeStatusListener(); //Load database items LoadData(); var endTime = GetTickCount(); Cnsl.Info(@"Initialization complete. Server loaded in " + (endTime - startTime) + " ms."); Cnsl.Banner(" Server has started successfully \n @ " + DateTime.UtcNow + " UTC"); Globals.Initialized = true; Cnsl.Finalize("Initializing Server"); }
public static void SendDataTo(int index, byte[] data) { var buffer = new ByteBuffer(); var compressed = Compress(data); buffer.WriteBytes(compressed); try { Client[index].myStream.Write(buffer.ToArray(), 0, buffer.ToArray().Length); } catch { Cnsl.Debug(@"Unable to send packet- client disconnected"); } buffer.Dispose(); }
public static void InitializePackets() { Cnsl.Debug("Initializing Network Packets", true); packets = new Dictionary <long, Packet> { { (long)ClientPackets.CMovement, PACKET_CLIENTMOVEMENT }, { (long)ClientPackets.CMessage, PACKET_CLIENTMESSAGE }, { (long)ClientPackets.CLogin, PACKET_LOGIN }, { (long)ClientPackets.CEquip, PACKET_EQUIP }, { (long)ClientPackets.CAttack, PACKET_ATTACK }, { (long)ClientPackets.CLoot, PACKET_LOOT }, { (long)ClientPackets.CShopBuy, PACKET_PURCHASE }, { (long)ClientPackets.CShopSell, PACKET_SELL }, { (long)ClientPackets.CDischarge, PACKET_DISCHARGE }, { (long)ClientPackets.CLog, PACKET_LOGERROR }, { (long)ClientPackets.CManufacture, PACKET_MANUFACTURE }, { (long)ClientPackets.CHangarBuy, PACKET_HANGAR }, }; Cnsl.Finalize("Initializing Network Packets"); }
private static void ConsoleThread() { var command = ""; var pulseTimer = new Timer(e => { if (Globals.Initialized) { ServerTcp.PreparePulseBroadcast(); } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(25)); // Recharge systems var rechargeTimer = new Timer(e => { if (Globals.Initialized) { _userService.RechargeSystems(); } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)); // Try a repop every 30 seconds // Remove old loots var repopTimer = new Timer(e => { if (Globals.Initialized) { _mobService.RepopGalaxy(); } if (Globals.Initialized) { _itemService.RemoveLoot(); } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(30000)); // Wander mobs everys 15 seconds var wanderTimer = new Timer(e => { if (Globals.Initialized) { _mobService.WanderMobs(); } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(15000)); // Save the game every 5 minutes var saveTimer = new Timer(e => { if (Globals.Initialized) { SaveGame(); } }, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(300000)); while (command != "end" && command != "e" && command != "exit" && command != "q" && command != "quit") { command = Console.ReadLine(); Console.CursorTop--; switch (command) { case "save": SaveGame(); break; case "": Cnsl.Debug("#"); break; default: if (command != "end" && command != "e" && command != "exit" && command != "q" && command != "quit") { Cnsl.Debug(@"Unknown Command"); } break; } } // Try one last save on exit SaveGame(); pulseTimer.Dispose(); repopTimer.Dispose(); wanderTimer.Dispose(); saveTimer.Dispose(); }
public static void LoadData() { Cnsl.Info(@"Preparing to load data:"); var items = 0; var startTime = GetTickCount(); Cnsl.Debug("Loading items", true); try { Globals.Items = Program._itemService.LoadItems(); Cnsl.Finalize("Loading items"); } catch { Cnsl.Finalize("Loading items", false); return; } items += Globals.Items.Count; Cnsl.Debug("Loading recipes", true); try { Globals.Recipes = Program._itemService.LoadRecipes(); Cnsl.Finalize("Loading recipes"); } catch { Cnsl.Finalize("Loading recipes", false); return; } Cnsl.Debug("Building hash table", true); try { PopulateHashTable(); Cnsl.Finalize("Building hash table"); } catch { Cnsl.Finalize("Building hash table", false); return; } items += Globals.Recipes.Count; Cnsl.Debug("Loading galaxy", true); try { Globals.Galaxy = Program._starService.LoadStars(); Globals.Structures = Program._starService.LoadStructures(); Cnsl.Finalize("Loading galaxy"); } catch { Cnsl.Finalize("Loading galaxy", false); return; } items += Globals.Galaxy.Count; items += Globals.Structures.Count; var endTime = GetTickCount(); Cnsl.Info(@"Data loaded (" + items + " points) in " + (endTime - startTime) + " ms."); }