public void ServerStats(DediStats data) { var sData = new ServerData { fps = data.fps, mem = data.mem, players = data.players, ticks = data.ticks, uptime = data.uptime, }; if (data.players == 0) { playerOfflineCount++; Thread.Sleep(1000); if (playerOfflineCount == 3600) { String sayCommand = "say Server Shutting Down Now in 5 mins"; String command = "saveandexit 5"; GameAPI.Game_Request(CmdId.Request_ConsoleCommand, (ushort)CmdId.Request_InGameMessage_AllPlayers, new PString(sayCommand)); GameAPI.Game_Request(CmdId.Request_ConsoleCommand, (ushort)CmdId.Request_InGameMessage_AllPlayers, new PString(command)); // Console.WriteLine("Commands: {0}", command); //Console.WriteLine("ConsoleCommand: {0}", GameAPI.Game_Request(CmdId.Request_ConsoleCommand, (ushort)CmdId.Request_InGameMessage_AllPlayers, new Eleon.Modding.PString(command))); } } else { playerOfflineCount = 0; } var json = JsonUtility.ToJson(sData, true); File.WriteAllText(@"E:\empyrionDedicatedserver\Content\Mods\ServerInfo\serverdata.json", json); }
private void ProcessEvent_Dedi_Stats(DediStats obj) { // from Request_Dedi_Stats DebugOutput("Event_Dedi_Stats - fps:{0}, mem:{1}, players:{2}, uptime:{3}, ticks:{4}", obj.fps, obj.mem, obj.players, obj.uptime, obj.ticks); }
public void Game_Event(CmdId eventId, ushort seqNr, object data) { try { switch (eventId) { case CmdId.Event_Dedi_Stats: DediStats dStats = (DediStats)data; ServerStats(dStats); break; case CmdId.Event_Player_Connected: { int entityId = ((Id)data).id; lock (playerIds) { playerIds.Add(entityId); } } break; case CmdId.Event_Player_Disconnected: { int entityId = ((Id)data).id; lock (playerIds) { playerIds.Remove(entityId); } } break; case CmdId.Event_Player_List: { if (data != null) { // empyt list is null?! lock (playerIds) { playerIds = ((IdList)data).list; } for (int i = 0; i < playerIds.Count; i++) { //GameAPI.Console_Write(string.Format("{0} Player with id {1}", i + 1, playerIds[i])); if (i > 0) { GetPlayerInfo(); } } } else { GameAPI.Console_Write("No players connected"); } } break; case CmdId.Event_Player_Info: { // DediStats sStats = (DediStats)data; PlayerInfo pInfo = (PlayerInfo)data; if (pInfo == null) { break; } Json.AddAndUpdatePlayer(pInfo); } break; } } catch (Exception ex) { GameAPI.Console_Write(ex.Message); } }