Ejemplo n.º 1
0
    public void MakeRequest()
    {
        string userId = UserStatics.GetUserId(0).ToString();

        GameObject.Find(Constants.softwareModel).GetComponent <SoftwareModel>().netwRout.TCPRequest(
            SetSessionIdAndGoToLobby,
            new string[] { "req", "sessId", "userId" },
            new string[] { "joinSession", sessionIDText.text, userId });
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Updates the user.
 /// </summary>
 /// <param name="user_update">User update.</param>
 public void UpdateUser(UpdateData user_update)
 {
     for (int i = 0; i < users.Count; i++)
     {
         if (UserStatics.GetUserId(i) == user_update.Id)
         {
             users [i].UpdateData = user_update;
         }
     }
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Handles the session start. Assigns the other users in the game-session to the respective GameObjects.
    ///
    /// Adds the plates to server and Starts socket, if none of the other users in the session has done so.
    ///
    /// CALLBACK FUNCTION FOR TCP-Request.
    /// </summary>
    /// <param name="response">Response.</param>
    private void HandleSessionStart(string[][] response)
    {
        string user_ref      = "";
        int    user_id       = 0;
        string user_name     = "";
        string sessionId     = UserStatics.SessionId.ToString();
        bool   startedSocket = false;

        foreach (string[] pair in response)
        {
            // Check, if session is already in running state, otherwise start it.
            if (pair [0].Equals("state") && !(pair [1].Equals(Constants.sfRunning) || pair [1].Equals(Constants.sfStarting)))
            {
                startedSocket = true;
                string plateIds = "";
                for (int i = 0; i < SoftwareModel.PlateContr.GetPlateCount(); i++)
                {
                    plateIds += i + (i < SoftwareModel.PlateContr.GetPlateCount() - 1 ? "//" : "");
                }
                SoftwareModel.netwRout.TCPRequest(
                    CollectPlateIds,
                    new string[] { "req", "sessionId", "plateIds" },
                    new string[] { "addPlatesToSession", sessionId, plateIds });

                string userId = UserStatics.GetUserId(0).ToString();
                SoftwareModel.netwRout.UDPRequest(
                    NetworkRoutines.EmptyCallback,
                    new string[] { "userId", "timer", "sessionId" },
                    new string[] { userId, levelTimer.ToString(), sessionId });
            }
            else if (pair[0].Equals("ur"))
            {
                user_ref = pair[1];
            }
            else if (pair[0].Equals("ui"))
            {
                int.TryParse(pair[1], out user_id);
            }
            else if (pair[0].Equals("un"))
            {
                user_name = pair[1];
                SoftwareModel.userController.AddUser(user_ref, user_id, user_name);
            }
        }
        // Collect the plateIds, if the session was started by somebody else:
        if (!startedSocket)
        {
            CollectPlateIds();
        }
        pauseMenu   = GameObject.Find("PauseMenuController").GetComponent <PauseMenu> ();
        timerScript = GameObject.Find("TimerText").GetComponent <TimerScript> ();

        WorkOnSocket();
    }
Ejemplo n.º 4
0
    /// <summary>
    /// Sets up the socket. Takes the timer, that determines the lifetime of the socket
    /// and thus the time to complete the level.
    /// </summary>
    /// <param name="timer">Timer.</param>
    public void SetSocket(int timer)
    {
        levelTimer = timer;
        // Create the socket, that communicates with server.
        socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

        string userId    = UserStatics.GetUserId(0).ToString();
        string sessionId = UserStatics.SessionId.ToString();

        SoftwareModel.netwRout.TCPRequest(
            HandleSessionStart,
            new string[] { "req", "sessionId", "userId" },
            new string[] { "startSession", sessionId, userId });
    }