public void GetMainCommand() { try { string reply = SendMessage(Server.ClientID, "main", Server.LastInfo); switch (reply) { case "Start": if (ClientApi.GetState() != ClientStates.Start) { Server.LoadedAccount = GetAccount(); if (Server.LoadedAccount == null) { Server.SetInfoText("Can't get account data."); } else { ClientApi.Start(); } } break; case "Login": ClientApi.SetState(ClientStates.Login); Logger.Log("Manager said: " + reply); break; case "Stop": ClientApi.Stop(); break; case "shutdown": break; } } catch (Exception x) { Logger.Log("Can't get commands. Details: " + x.Message); } }
public Communication(Server server) { string ip = System.IO.File.ReadAllText("local.txt").TrimEnd('\n'); Server = server; Server.ClientID = 0; StartServer(ip, Server.PORT); int id = GetAvailableClientID(); if (id == 0) { CloseInSeconds("Can't find available ID in manager."); } else { Server.ClientID = id; Server.SetInfoText($"Registering ID {id}..."); if (SendMessage(id, "register") == "true") { Server.SetInfoText($"Success."); } else { CloseInSeconds("Can't register ID."); } } if (Server.ClientID != 0) { // id set new ClientApi(server); ClientApi.SetState(ClientStates.Idle); KillMainTimer(); MainTimer = new System.Threading.Timer(TimerCallback, null, TIMER_INTERVAL, Timeout.Infinite); } }