示例#1
0
        /// <summary>
        /// Callback for when the user receieves data from the server.
        /// Sets initial player cube if we don't have it.
        /// Otherwise it sets all of the new cubes in the world.
        /// Asks for more data from the server.
        /// </summary>
        /// <param name="state"></param>
        private void receiveDataFunc(Preserved_Socket_State state)
        {
            lock (worldInfo)
            {
                state.sb.Append(encoding.GetString(state.buffer, 0, state.bytesRead));
                string response = state.sb.ToString();
                string lastCube = worldInfo.updateCubes(response);
                state.sb.Replace(response, lastCube);
                this.Invalidate();

                Network.i_want_more_data(state);
            }
        }
示例#2
0
        /// <summary>
        /// Callback that happens when we receive the player data from the
        /// server.
        /// </summary>
        /// <param name="state"></param>
        private void receivePlayerFunc(Preserved_Socket_State state)
        {
            lock (worldInfo)
            {
                actionCallback handler = receiveDataFunc;
                state.callback = handler;

                state.sb.Append(encoding.GetString(state.buffer, 0, state.bytesRead));
                string response = state.sb.ToString();

                Cube playerCube = JsonConvert.DeserializeObject <Cube>(response);
                playerCubeUid = playerCube.uid;

                worldInfo.addCube(playerCube);
                hasPlayerCube = true;

                this.Invalidate();

                Network.i_want_more_data(state);
            }
        }