static void Main(string[] args) { // Load config Configuration.ConfigurationFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Config/server.json"); // Write welcome banner WriteBanner(); // Setup logging // File if (!Directory.Exists("Logs")) { Directory.CreateDirectory("Logs"); } Logger.RegisterLogger(new FileLogger(Path.Combine(Directory.GetCurrentDirectory(), "Logs/server.log"), true) { LogLevel = LogLevel.Info }); // Console ConsoleLogger.Instance.LogLevel = Configuration.Global.ConsoleLogLevel; // Startup "Logging started!".Info(); "Reading shop data...".Info(); ShopDataReader.ReadGoods(); "Done!".Info(); "Reading poo data...".Info(); PooReader.ReadPoo(); "Done!".Info(); "Reading map data...".Info(); GeoEngine.GeoEngine.LoadAllMaps(); "Done!".Info(); $"Server Port is {Configuration.Global.GamePort}".Info(); "Server starting...".Info(); var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; RunServers(token); "Server is Started!".Info(); // Temp room // var instance = new GameInstance // { // //Server = sessionServer, // Capacity = 7, // GameTemplate = 10809, // GameType = GameType.Survival, // MasterId = 1, // GameStatus = GameStatus.InBattle, // GameIsStarted = true, // Name = "FACE OFF 24 seven", // SpawnLocation = new Vector3(0, 0, 80) // }; // instance.LoadMap("faceonface"); // RoomManager.CreateRoom(instance); // instance.StartGameLoop(); // // instance = new GameInstance // { // //Server = sessionServer, // Capacity = 8, // GameTemplate = 50820, // GameType = GameType.CaptureTheFlag, // MasterId = 1, // GameStatus = GameStatus.InBattle, // GameIsStarted = true, // Name = "VHill CTF", // SpawnLocation = new Vector3(1000, 0, 2000) // }; // // instance.LoadMap("Vhill"); // RoomManager.CreateRoom(instance); // instance.StartGameLoop(); // // instance = new GameInstance // { // //Server = sessionServer, // Capacity = 100, // GameTemplate = 11610, // GameType = GameType.Survival, // MasterId = 1, // GameStatus = GameStatus.InBattle, // GameIsStarted = true, // Name = "Battle Royale?", // SpawnLocation = new Vector3(0, 0, 1000) // }; // // instance.LoadMap("Tridentway"); // RoomManager.CreateRoom(instance); // instance.StartGameLoop(); // instance = new GameInstance // { // //Server = sessionServer, // Capacity = 1, // GameTemplate = 10800, // GameType = GameType.Tutorial, // MasterId = 1, // GameStatus = GameStatus.InBattle, // GameIsStarted = true, // Name = "Tutorial", // SpawnLocation = new Vector3(4673, 191, -3168) // }; //instance.LoadMap("tutorial"); //RoomManager.CreateRoom(instance); "Creating chat channels...".Info(); // Create main chat channel ChatManager.CreateChannel(new ChatChannel { Name = "EXTEEL.NETβ€οΈ", OnConnect = (s, c) => { // This doesnt work yet. possibly sending too early? c.SendMessageToSession(s, "Welcome to the Exteel.Net private server!"); } }); "Done!".Info(); "Press Enter to stop the server or '!' to restart the server...".Info(); // Docker support // Handle Control+C or Control+Break Console.CancelKeyPress += (o, e) => { Console.WriteLine("Exit"); tokenSource.Cancel(); // Allow the manin thread to continue and exit... WaitHandle.Set(); }; // Wait WaitHandle.WaitOne(); /* * // Perform text input * for (;;) * { * string line = Console.ReadLine(); * if (string.IsNullOrEmpty(line)) * break; * * // Restart the server * if (line == "!") * { * Console.Write("Server restarting..."); * server.Restart(); * Console.WriteLine("Done!"); * continue; * } * * // Multicast admin message to all sessions * // TODO: Handle admin commands * * if (line[0] == '/') * { * var data = Regex.Matches(line, @"[\""].+?[\""]|[^ ]+") * .Select(x => x.Value.Trim('"')) * .ToList(); * * switch (data[0]) * { * case "/chat": * //sessionServer.Multicast(new Message(data[1], data[2], Convert.ToInt32(data[3]), * //Convert.ToInt32(data[4])).Write()); * * server.Multicast(new Message(data[1], data[2], Convert.ToInt32(data[3]), * Convert.ToInt32(data[4])).Write()); * break; * * case "/notice": * ChatManager.BroadcastAll("π½π½π½π½π½π½π½π½π½π½π½"); * ChatManager.BroadcastAll("π½π½γπγNOTICEγπγπ½π½"); * ChatManager.BroadcastAll("π½π½π½π½π½π½π½π½π½π½π½"); * * ChatManager.BroadcastAll(data[1]); * * server.Multicast(new Message("γπγNOTICEγπγ", data[1]).Write()); * break; * } * } * }*/ // Stop the server "Server stopping...".Info(); "Done!".Info(); Terminal.Flush(); }
protected override void RunImpl() { var client = GetClient(); using (var db = new ExteelContext()) { // Get tracked entity var user = db.Users .Include(u => u.Inventory) .ThenInclude(i => i.Parts) .Single(u => u.Id == client.User.Id); Console.WriteLine("Found user " + user.Id); // Lookup good var good = ShopDataReader.GetGoodById(_goodId); // Subtract money // TODO: Handle Coins user.Credits -= good.CreditPrice; // Create Parts foreach (var templateId in good.Templates) { PartRecord partRecord; var partsType = (int)templateId; while (partsType >= 10) { partsType /= 10; } // Check if its a code if (templateId < 300) { partRecord = new Code(); partRecord.Type = (byte)9; } // Check for weapon else if (partsType == 6 || partsType == 7 || partsType == 8) { partRecord = new Weapon(); partRecord.Type = (byte)partsType; } else { partRecord = new PartRecord(); partRecord.Type = (byte)partsType; } // Populate info partRecord.TemplateId = templateId; partRecord.Parameters = 1; partRecord.Color = Color.White; // Add to inventory user.Inventory.Parts.Add(partRecord); //db.Parts.Add(part); } // Save to DB db.SaveChanges(); } GetClient().UpdateUserFromDatabase(); // Send result GetClient().SendPacket(new BuyListResult(GetClient().User)); }