void Start()
    {
        if (started_ || manualTest)
        {
            return;
        }

        started_ = true;

        FunapiDedicatedServer.Start("1.0.0.1");

        if (FunapiDedicatedServer.isServer)
        {
            FunapiDedicatedServer.UserDataCallback  += onReceivedUserData;
            FunapiDedicatedServer.MatchDataCallback += onReceivedMatchData;
            FunapiDedicatedServer.StartCallback     += delegate()
            {
                FunDebug.Log("Start callback......");
            };
            FunapiDedicatedServer.DisconnectedCallback += delegate()
            {
                FunDebug.Log("Disconnected callback......");
#if UNITY_EDITOR
                UnityEditor.EditorApplication.Exit(0);
#else
                Application.Quit();
#endif
                return;
            };

            StartCoroutine(startServer());
        }
    }
    public bool AuthUser(string user_id, string token)
    {
        if (manualTest)
        {
            return(true);
        }

        return(FunapiDedicatedServer.AuthUser(user_id, token));
    }
示例#3
0
    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 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
            }
        });
    }