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"); }
private static void PACKET_LOGERROR(int connectionId, byte[] data) { var buffer = new ByteBuffer(); buffer.WriteBytes(data); buffer.ReadLong(); var message = buffer.ReadString(); buffer.Dispose(); Cnsl.Warn(message); }
public static void SaveGame() { Cnsl.Log("Saving game", true); try { _gameService.SaveGame(_userService.ActiveUsers.ToList()); Cnsl.Finalize("Saving game"); } catch { Cnsl.Finalize("Saving game", false); } }
public static void InitializeStatusListener() { try { statusSocket = new TcpListener(IPAddress.Any, Constants.STATUS_PORT); statusSocket.Start(); statusSocket.BeginAcceptTcpClient(OnStatusRequest, null); Cnsl.Finalize("Initializing Status Listener"); } catch { Cnsl.Finalize("Initializing Status Listener", false); } }
public static void InitializeNetwork() { try { serverSocket = new TcpListener(IPAddress.Any, Constants.PORT); serverSocket.Start(); serverSocket.BeginAcceptTcpClient(OnClientConnect, null); Cnsl.Finalize("Initializing Network"); } catch { Cnsl.Finalize("Initializing Network", false); } Console.Title = @"Project Sol Server | " + Constants.PORT; }
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 void CloseSocket(int index) { Cnsl.Log("Connection from " + ip + " has been terminated"); var player = Program._userService.ActiveUsers.Find(p => p.Id == Globals.PlayerIDs[index]); if (player != null) { ServerTcp.SendMessage(-1, player.Name + @" has disconnected.", (int)ChatPackets.Notification); player.inGame = false; player.receiving = false; } Program._gameService.SaveGame(new List <User> { player }); socket.Close(); socket = null; Globals.PlayerIDs[index] = null; Program._userService.ActiveUsers.Remove(player); }
private static void PACKET_LOGIN(int connectionId, byte[] data) { var buffer = new ByteBuffer(); buffer.WriteBytes(data); buffer.ReadLong(); var user = buffer.ReadString(); var pass = buffer.ReadString(); var validate = Program._userService.PasswordOK(user, pass); if (!validate) { ServerTcp.SendSystemByte(connectionId, SystemBytes.SysInvPass); return; } buffer.Dispose(); var player = Program._userService.LoadPlayer(user); player.inGame = true; player.connectionID = connectionId; Globals.PlayerIDs.Add(connectionId, player.Id); Program._userService.ActiveUsers.Add(player); ServerTcp.SendGlobals(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendItems(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendToGalaxy(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendIngame(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendInventory(connectionId); //ServerTCP.SendNebulae(connectionID); ServerTcp.SendMessage(-1, player.Name + " has connected.", (int)ChatPackets.Notification); System.Threading.Thread.Sleep(250); ServerTcp.SendGalaxy(connectionId); System.Threading.Thread.Sleep(250); ServerTcp.SendRecipes(connectionId); Globals.FullData = true; Cnsl.Log(user + @" logged in successfully."); player.receiving = true; }
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 OnClientConnect(IAsyncResult result) { var client = serverSocket.EndAcceptTcpClient(result); serverSocket.BeginAcceptTcpClient(OnClientConnect, null); var port = ((IPEndPoint)client.Client.RemoteEndPoint).Port; if (!Client.ContainsKey(port)) { var newClient = new Clients { socket = client, connectionID = port, ip = client.Client.RemoteEndPoint.ToString() }; Client.Add(port, newClient); Client[port].Start(); Cnsl.Log("Connection received from " + Client[port].ip); return; } }
static void Main(string[] args) { Console.WriteLine("Please, input your text:"); string ILine = Console.ReadLine(); int option; Console.WriteLine("Please, select method of output (1 - Console, 2 - File, 3 - Picture. 0 - Cancel):"); option = Convert.ToInt32(Console.ReadLine()); switch (option) { case 1: Cnsl m = new Cnsl(ILine); m.Print(ILine); break; case 2: Fl n = new Fl(ILine); n.Print(ILine); break; //case 3: } }
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."); }