void onReceivedMessage(string type, object message) { if (type == "echo") { Dictionary <string, object> json = message as Dictionary <string, object>; FunDebug.Log("[{0}] received: {1}", client_id, json["message"] as string); } else if (type == "pbuf_echo") { FunMessage msg = message as FunMessage; object obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_echo); if (obj == null) { return; } PbufEchoMessage echo = obj as PbufEchoMessage; FunDebug.Log("[{0}] received: {1}", client_id, echo.msg); } }
IEnumerator OnEnd() { RpcEnd(winnerId); Dictionary <string, object> result = new Dictionary <string, object>(); result["winner"] = winnerId; result["winner_uid"] = players_[winnerId].user_id; result["loser_uid"] = players_[loserId].user_id; Dictionary <string, object> json = new Dictionary <string, object>(); json["result"] = result; string json_string = FunapiMessage.JsonHelper.Serialize(json); FunapiDedicatedServer.SendResult(json_string, delegate(int error_code, string error_desc) { FunDebug.LogWarning("SendResult cb. code : {0}, desc : {1}", error_code, error_desc); if (error_code != 0) { FunDebug.Log("SendResult error. code : {0}, desc : {1}", error_code, error_desc); #if UNITY_EDITOR UnityEditor.EditorApplication.Exit(0); #else Application.Quit(); #endif } }); yield return(new WaitForSeconds(1f)); foreach (Player player in players_.Values) { onPlayerLeft(player); } yield return(new WaitForSeconds(3f)); LobbyManager.s_Singleton.StopServerClbk(); players_.Clear(); }
void start() { writeTitle("START"); FunDebug.Log("Client count is {0}.", kClientMax); for (int i = 0; i < kClientMax; ++i) { Client client = new Client(i, kServerIp); list_.Add(client); } Thread t = new Thread(new ThreadStart(onUpdate)); t.Start(); testConnect(); testStartStop(); testSendReceive(); t.Abort(); }
void onReceivedMessage(string type, object message) { if (type == "echo") { Dictionary <string, object> json = message as Dictionary <string, object>; string echo_msg = json["message"] as string; FunDebug.Log("[{0}:{2}] {1}", id_, echo_msg, ++message_number_); } else if (type == "pbuf_echo") { FunMessage msg = message as FunMessage; object obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_echo); if (obj == null) { return; } PbufEchoMessage echo = obj as PbufEchoMessage; FunDebug.Log("[{0}:{2}] {1}", id_, echo.msg, ++message_number_); } }
void onReceivedMatchData(string json_string) { if (send_ready_) { return; } send_ready_ = true; FunapiDedicatedServer.SendReady(delegate(int error_code, string error_desc) { FunDebug.LogWarning("SendReady cb. code : {0}, desc : {1}", error_code, error_desc); if (error_code != 0) { FunDebug.LogWarning("SendReady error. code : {0}, desc : {1}", error_code, error_desc); #if UNITY_EDITOR UnityEditor.EditorApplication.Exit(0); #else Application.Quit(); #endif } }); }
static void onMulticastChannelList(FunEncoding encoding, object channel_list) { if (encoding == FunEncoding.kJson) { List <object> list = channel_list as List <object>; if (list.Count <= 0) { FunDebug.Log("[Channel List] There are no channels."); return; } StringBuilder data = new StringBuilder(); data.Append("[Channel List]\n"); foreach (Dictionary <string, object> info in list) { data.AppendFormat("name:{0} members:{1}", info["_name"], info["_members"]); data.AppendLine(); } FunDebug.Log(data.ToString()); } else { List <FunMulticastChannelListMessage> list = channel_list as List <FunMulticastChannelListMessage>; if (list.Count <= 0) { FunDebug.Log("[Channel List] There are no channels."); return; } StringBuilder data = new StringBuilder(); data.Append("[Channel List]\n"); foreach (FunMulticastChannelListMessage info in list) { data.AppendFormat("name:{0} members:{1}", info.channel_name, info.num_members); data.AppendLine(); } FunDebug.Log(data.ToString()); } }
void OnReceive(string type, object obj) { FunEncoding encoding = session_.GetEncoding(); string result = ""; if (type == "fb_authentication") { if (encoding == FunEncoding.kJson) { Dictionary <string, object> message = obj as Dictionary <string, object>; result = message["result"].ToString(); } else if (encoding == FunEncoding.kProtobuf) { FunMessage msg = obj as FunMessage; PbufAnotherMessage message = FunapiMessage.GetMessage <PbufAnotherMessage>(msg, MessageType.pbuf_another); result = message.msg; } if (result == "ok") { logged_in_ = true; if (image_ != null && facebook_.MyPicture != null) { image_.texture = facebook_.MyPicture; } setButtonState(true); } else { FunDebug.Log("facebook login authenticatiion failed."); facebook_.Logout(); } } }
void start() { writeTitle("START"); FunDebug.Log("Client count is {0}.\n", kClientMax); int testCount = 0; while (testCount < kTestCount) { ++testCount; for (int i = 1; i <= kClientMax; ++i) { Thread t = new Thread(new ThreadStart(onTest)); t.IsBackground = true; threads_.Add(t); t.Start(); } foreach (Thread t in threads_) { t.Join(); } threads_.Clear(); Thread.Sleep(1000); writeTitle("Test Set '" + testCount + "' has been finished."); } FunapiMono.Stop(); writeTitle("FINISHED"); Process.GetCurrentProcess().Kill(); }
public void SendEchoMessage(TransportProtocol protocol) { FunapiSession.Transport transport = session.GetTransport(protocol); if (transport == null) { FunDebug.LogWarning("SendEchoMessage - transport is null."); return; } if (transport.encoding == FunEncoding.kJson) { Dictionary <string, object> message = new Dictionary <string, object>(); message["message"] = string.Format("{0} echo message", transport.str_protocol); session.SendMessage("echo", message, protocol); } else if (transport.encoding == FunEncoding.kProtobuf) { PbufEchoMessage echo = new PbufEchoMessage(); echo.msg = string.Format("{0} echo message", transport.str_protocol); FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo); session.SendMessage("pbuf_echo", message, protocol); } }
void onMaintenanceMessage(object message) { if (encoding_ == FunEncoding.kJson) { JsonAccessor json_helper = FunapiMessage.JsonHelper; FunDebug.Log("Maintenance message\nstart: {0}\nend: {1}\nmessage: {2}", json_helper.GetStringField(message, "date_start"), json_helper.GetStringField(message, "date_end"), json_helper.GetStringField(message, "messages")); } else if (encoding_ == FunEncoding.kProtobuf) { FunMessage msg = message as FunMessage; object obj = FunapiMessage.GetMessage(msg, MessageType.pbuf_maintenance); if (obj == null) { return; } MaintenanceMessage maintenance = obj as MaintenanceMessage; FunDebug.Log("Maintenance message\nstart: {0}\nend: {1}\nmessage: {2}", maintenance.date_start, maintenance.date_end, maintenance.messages); } }
void onDownloadUpdate(string path, long bytes_received, long total_bytes, int percentage) { FunDebug.DebugLog("Downloading - path:{0} / received:{1} / total:{2} / {3}%", path, bytes_received, total_bytes, percentage); }
void onReceived(string msg_type, object body) { Dictionary <string, object> message = body as Dictionary <string, object>; if (msg_type == "_sc_dedicated_server") { Dictionary <string, object> redirect = message["redirect"] as Dictionary <string, object>; string ip = redirect["host"] as string; int port = Convert.ToInt32(redirect["port"]); token_ = redirect["token"] as string; LobbyManager.s_Singleton.networkAddress = ip; LobbyManager.s_Singleton.networkPort = port; if (mainMenu != null) { mainMenu.StartJoin(); } } else if (msg_type == "login") { Dictionary <string, object> err_data = message["error"] as Dictionary <string, object>; int error_code = Convert.ToInt32(err_data["code"]); string error_desc = err_data["message"] as string; if (error_code == 200) // success { // { // "account_id": "id", // "match_type": 1 // "user_data": { // "level": 70, // "ranking_score": 1500, // ... // }, // } Dictionary <string, object> match = new Dictionary <string, object>(); match["account_id"] = user_id_; match["match_type"] = 1; Dictionary <string, object> user_data = new Dictionary <string, object>(); user_data["level"] = 1; user_data["mmr_score"] = 100; match["user_data"] = user_data; session_.SendMessage("match", match); } else { if (mainMenu != null) { mainMenu.lobbyManager.DisplayIsLoginFailed(); } FunDebug.Log("Login failed.({0}, code : {1})", error_desc, error_code); session_.Stop(); } } else if (msg_type == "logout") { signing_out_ = true; Dictionary <string, object> err_data = message["error"] as Dictionary <string, object>; int error_code = Convert.ToInt32(err_data["code"]); string error_desc = err_data["message"] as string; if (error_desc.ToLower() != "ok") { if (mainMenu != null) { string str = string.Format("logout. {0}", error_desc); mainMenu.lobbyManager.DisplayIsError(str); } } FunDebug.Log("Logout.({0}, code : {1})", error_desc, error_code); session_.Stop(); } }
void onDownloadVerify(string path) { FunDebug.DebugLog("Check file - {0}", path); }
public void OnClickHost() { FunDebug.Log("OnClickHost()"); lobbyManager.StartHost(); }
void onChatReceived(string chat_channel, string sender, string text) { FunDebug.Log("Received a chat channel message.\nChannel={0}, sender={1}, text={2}", chat_channel, sender, text); }
void dashLog(string text) { FunDebug.Log(string.Format("---------- {0} ----------", text)); }
void onResponseTimedOut(string type) { FunDebug.Log("Response timed out. type: {0}", type); }