public static ProtoMessage GetActionReply(Actions action, TextTestClient client)
    {
        bool         receivedActionReply = false;
        bool         receivedUpdateReply = false;
        ProtoMessage reply;
        ProtoMessage actionReply = null;

        if (action == Actions.LogIn)
        {
            receivedUpdateReply = true;
        }

        //int elapsed = 0;
        do
        {
            //reply = client.GetReply();
            reply = client.CheckForProtobufMessage();
            if (reply == null)  // wait time expired.
            {
                globalString = "You have been disconnected.";
                tclient.LogOut();
                GoToScene(SceneName.LogIn);
                return(null);
            }

            if (reply.ActionType == action)
            {
                Debug.Log("Correct action found: " + reply.ActionType.ToString() + " /w " + reply.ResponseType.ToString());
                actionReply         = reply;
                receivedActionReply = true;
            }
            else if (reply.ActionType == Actions.Update)
            {
                Debug.Log("Update action found: " + reply.ActionType.ToString() + " /w " + reply.ResponseType.ToString());
                if (reply.ResponseType == DisplayMessages.ErrorGenericMessageInvalid)
                {
                    actionReply         = reply; // When the server found something wrong with the action.
                    receivedActionReply = true;
                }
                //else if(reply.ResponseType == DisplayMessages.Error) {
                //    receivedUpdateReply = true; // LogIn Failure.
                //}
                else if (reply.ResponseType == DisplayMessages.Success)
                {
                    protoClient         = (ProtoClient)reply;
                    receivedUpdateReply = true;
                }
            }
            else
            {
                Debug.Log("Mismatching action found: " + reply.ActionType.ToString() + " /w " + reply.ResponseType.ToString());
            }

//            Thread.Sleep(10);
//            elapsed += 10;
//            if(elapsed > 5000) {
//#if UNITY_EDITOR
//                UnityEditor.EditorApplication.isPlaying = false;
//#endif
//            }
        } while(!receivedActionReply || !receivedUpdateReply);

        return(actionReply);

        //ProtoMessage responseTask = client.GetReply();

        //while(responseTask.ActionType != action) {
        //    responseTask = client.GetReply();
        //}
        //client.ClearMessageQueues();
        //return responseTask;
    }
Esempio n. 2
0
 private static void Shutdown()
 {
     _testClient.LogOut();
 }