public HFTGame(string id, HFTGameGroup group, HFTRuntimeOptions options) { id_ = id; gameGroup_ = group; options_ = options; SetGameId(); log_ = new HFTLog("HFTGame[" + gameId_ + "]"); log_.Info("created game"); }
IEnumerator InformCoroutine() { var headers = new Dictionary <string, string>(); headers["Content-Type"] = "application/json"; headers["Host"] = domain_; www_ = new WWW(url_, addressesBytes_, headers); yield return(www_); string err = www_.error; string result = www_.text; www_ = null; // Was it successful? if (String.IsNullOrEmpty(err)) { // Yes log_.Info("registered: " + addressesStr_ + " with " + domain_ + " for: " + result); done_ = true; sharedState_.success = true; } else { ++tryCount_; if (tryCount_ > 2 && !sharedState_.success) { log_.Info("Try " + tryCount_ + " of " + kMaxTries + ": Could not contact: " + domain_ + "[" + url_ + "]\nSTATUS: " + result); } if (tryCount_ >= kMaxTries || tryCount_ > 1 && sharedState_.success) { done_ = true; } } informCoroutine_ = null; }
public HFTWebServer(HFTRuntimeOptions options, string[] addresses) { m_log = new HFTLog("HFTWebServer"); m_options = options; m_gamePath = "/"; m_webServerUtils = new HFTWebServerUtils(m_gamePath); // Touch the HFTWebFileDB // We do this be because we want it to get the list // of files BEFORE run the server. The server will // run in a different thread and HFTWebFileDB will // not be able to populate its database from that thread. HFTWebFileDB.GetInstance(); // FIX: sysname and gamename string sysName = Environment.MachineName; if (sysName.EndsWith(".local")) { sysName = sysName.Substring(0, sysName.Length - 6); } string gameName = m_options.name; string ping = Serializer.Serialize(new HFTPing(sysName + ": " + gameName, "HappyFunTimes")); m_ping = System.Text.Encoding.UTF8.GetBytes(ping); m_log.Info("Ping: " + ping); m_liveSettingsStr = "define([], function() { return " + Serializer.Serialize(new LiveSettings()) + "; })\n"; m_liveSettings = System.Text.Encoding.UTF8.GetBytes(m_liveSettingsStr); if (options.captivePortal || options.installationMode) { m_captivePortalHandler = new HFTCaptivePortalHandler(m_webServerUtils); m_getRouter.Add(m_captivePortalHandler.HandleRequest); } m_getRouter.Add(HandleRoot); m_getRouter.Add(HandleLiveSettings); m_getRouter.Add(HandleFile); m_getRouter.Add(HandleMissingRoute); m_getRouter.Add(HandleNotFound); m_postCmdHandlers["happyFunTimesPingForGame"] = HandleCmdPingForGame; m_postCmdHandlers["happyFunTimesPing"] = HandleCmdPing; m_postCmdHandlers["happyFunTimesRedir"] = HandleCmdRedir; m_postCmdHandlers["time"] = HandleCmdTime; m_postCmdHandlers["quit"] = HandleCmdQuit; m_addresses = addresses; }
IEnumerator InformCoroutine() { www_ = new UnityWebRequest(url_, UnityWebRequest.kHttpVerbPOST); www_.uploadHandler = new UploadHandlerRaw(addressesBytes_); www_.uploadHandler.contentType = "application/json"; www_.downloadHandler = new DownloadHandlerBuffer(); yield return(www_.Send()); bool isError = (www_.isNetworkError || www_.isHttpError); string result = www_.downloadHandler.text; www_ = null; // Was it successful? if (!isError) { // Yes log_.Info("registered: " + addressesStr_ + " with " + domain_ + " for: " + result); done_ = true; sharedState_.success = true; } else { ++tryCount_; if (tryCount_ > 2 && !sharedState_.success) { log_.Info("Try " + tryCount_ + " of " + kMaxTries + ": Could not contact: " + domain_ + "[" + url_ + "]\nSTATUS: " + result); } if (tryCount_ >= kMaxTries || tryCount_ > 1 && sharedState_.success) { done_ = true; } } informCoroutine_ = null; }
public HFTPlayer(HFTSocket client, HFTGameManager server, string id) { client_ = client; gameManager_ = server; id_ = id; log_ = new HFTLog("HFTPlayer[" + id + "]"); log_.Info("start player"); client.OnMessageEvent += HandleMessage; client.OnCloseEvent += HandleDisconnect; RegisterCmdHandler <AddPlayerToGameMessage>("join", AddPlayerToGame); RegisterCmdHandler <HFTRuntimeOptions>("server", AssignAsServerForGame); RegisterCmdHandler <object>("update", PassMessageFromPlayerToGame); }