public static void Gifts_Req(InPacket lea, Client c) { int ItemID = lea.ReadInt(); string ItemName = lea.ReadString(62); string CharacterName = lea.ReadString(20); int Type = 1; if (CashShopFactory.GetItemData(ItemID) == null) { return; } c.Account.GamePoints -= CashShopFactory.GetItemData(ItemID).BargainPrice; c.Account.Save(); dynamic datum = new Datum("gifts"); datum.name = CharacterName; datum.itemID = ItemID; datum.itemName = ItemName; datum.receive = 0; datum.Insert(); CashShopPacket.Gifts(c, Type); CashShopPacket.MgameCash(c); CashShopPacket.GuiHonCash(c); }
public static void BuyCommodity_Req(InPacket lea, Client c) { int ItemID = lea.ReadInt(); string ItemName = lea.ReadString(62); short Quantity = 1; bool IsLocked = true; var chr = c.Character; if (CashShopFactory.GetItemData(ItemID) == null) { return; } if (ItemID == 8842002) { Quantity = 10; } if (ItemID == 8841001 || ItemID == 8841002 || ItemID == 8841003 || ItemID == 8841004 || ItemID == 8841005) { Quantity = 20; } if (ItemID == 8890031 || ItemID == 8890037) // 鞭炮 + 心花怒放 { Quantity = 100; } if (ItemID / 100000 == 92 || ItemID == 8890031 || ItemID == 8890037) // 寵物 + 鞭炮 + 心花怒放 { IsLocked = false; } // 購買日誌 dynamic datum = new Datum("BuyCommodityLog"); datum.name = chr.Name; datum.itemID = ItemID; datum.itemName = ItemName; datum.Insert(); c.Account.GamePoints -= CashShopFactory.GetItemData(ItemID).BargainPrice; c.Account.Save(); chr.Items.Add(new Item(ItemID, IsLocked, 0, -1, (byte)InventoryType.ItemType.Cash, chr.Items.GetNextFreeSlot(InventoryType.ItemType.Cash), Quantity)); chr.Items.Save(); CashShopPacket.BuyCommodity(c); CashShopPacket.MgameCash(c); CashShopPacket.GuiHonCash(c); InventoryPacket.getInvenCash(c); }
private static void Main(string[] args) { int port = 0; Log.SetLogFile(".\\Logs\\GameLog.log"); start: GameServer.Clients = new List <Client>(); Log.Entitle("Game Server v.{0}.{1}", 10, 10); try { if (port == 0) { try { port = int.Parse(args[0]); } catch { //port = Log.Input("Port[15101]: ", 15101); port = 15101; Log.Inform("Default Game Server Port: {0}", port); } } Settings.Initialize(); GameServer.AutoRestartTime = 15; // TODO: Get actual restart-time. Log.Inform("Automatic restart time set to {0} seconds.", GameServer.AutoRestartTime); Database.Test(); Database.Analyze(false); GameServer.RemoteEndPoint = new IPEndPoint(IPAddress.Parse(ServerConstants.LISTENER_SERVER_IP), port); // TODO: Get actual host. Log.Load("Items Initialize"); ItemFactory.Initialize(); Log.Success("\r\n"); Log.Load("Maps Initialize"); MapFactory.Initialize(); Log.Success("\r\n"); MobFactory.InitializeMonsterDrop(); CashShopFactory.InitializeHatCommodity(); CashShopFactory.InitializeMantleCommodity(); CashShopFactory.InitializeBoyDressCommodity(); CashShopFactory.InitializeGirlDressCommodity(); CashShopFactory.InitializeBoyHairCommodity(); CashShopFactory.InitializeGirlHairCommodity(); CashShopFactory.InitializeFace1Commodity(); CashShopFactory.InitializeFace2Commodity(); CashShopFactory.InitializeBoyEyesCommodity(); CashShopFactory.InitializeGirlEyesCommodity(); CashShopFactory.InitializePetCommodity(); CashShopFactory.InitializeAmuletCommodity(); CashShopFactory.InitializeTalismanCommodity(); CashShopFactory.InitializeProduceCommodity(); UdpRemoteEndPoint = new IPEndPoint(IPAddress.Parse(ServerConstants.SERVER_IP), ServerConstants.UDP_PORT); UdpListener = new UdpClient(UdpRemoteEndPoint); Log.Inform("Initialized clients UDP listener on {0}. Port {1}", UdpRemoteEndPoint.Address, UdpRemoteEndPoint.Port); GameServer.Listener = new TcpListener(IPAddress.Any, GameServer.RemoteEndPoint.Port); GameServer.Listener.Start(); Log.Inform("Initialized clients listener on {0}.", GameServer.Listener.LocalEndpoint); GameServer.IsAlive = true; } catch (Exception e) { Log.Error(e); } if (GameServer.IsAlive) { Log.Success("Server started on thread {0}.", Thread.CurrentThread.ManagedThreadId); AppDomain.CurrentDomain.UnhandledException += (s, e) => { Log.Error("Unhandled exception from Server: \n{0}", e.ExceptionObject.ToString()); }; new Thread(new ThreadStart(InteroperabilityClient.Main)).Start(); } else { Log.Inform("Could not start server because of errors."); } while (GameServer.IsAlive) { GameServer.AcceptDone.Reset(); GameServer.Listener.BeginAcceptSocket(new AsyncCallback(GameServer.OnAcceptSocket), null); GameServer.AcceptDone.WaitOne(); } Client[] remainingClients = GameServer.Clients.ToArray(); foreach (Client client in remainingClients) { client.Dispose(); } GameServer.Dispose(); Log.Warn("Server stopped."); if (GameServer.AutoRestartTime > 0) { Log.Inform("Attempting auto-restart in {0} seconds.", GameServer.AutoRestartTime); Thread.Sleep(GameServer.AutoRestartTime * 1000); goto start; } else { Console.Read(); } }