Ejemplo n.º 1
0
        public Envelope <SynchronizationMessage> Sync(Hksyn.Query query)
        {
            var date = DateTime.Now;
            var sync = new SynchronizationMessage(session.SystemId, date, user.Blz, user.UserId, connection.ProductId, connection.ProductVersion, query, user.Pin);
            var env  = new Envelope <SynchronizationMessage>(sync, date, user.Blz, user.UserId, session.SystemId);

            return(env);
        }
Ejemplo n.º 2
0
        public void Serialize_ShouldCalculateCorrectLength()
        {
            var date = DateTime.Now;
            var msg  = new SynchronizationMessage("0", date, 76550000, "760794644", "abc", "0.1", Hksyn.Query.SystemId, "1234");
            var env  = new Envelope <SynchronizationMessage>(msg, date, 76550000, "760794644", "0");

            var ser = env.Serialize();

            //env = FinTsParser.Parse<Envelope<SynchronizationMessage>>(ser);

            Assert.Equal(ser.Length, env.Header.Size.Value);
        }
Ejemplo n.º 3
0
    byte[] collectData2()
    {
        GameObject[]   activeObj;
        GameObject[][] tmpContainer;
        byte[]         syncbytes;
        //if (isSever && isPlaying)
        {
            players = GameObject.FindGameObjectsWithTag("Player");
            enemys  = GameObject.FindGameObjectsWithTag("enemy");
            // weapon= GameObject.FindGameObjectsWithTag("weapon");
            tmpContainer = new GameObject[][] { players, enemys };
            int activeGobjnum = players.Length + enemys.Length;
            activeObj = new GameObject[activeGobjnum];
            // SyncPosition = new Vector3[activeGobjnum];
            players.CopyTo(activeObj, 0);
            enemys.CopyTo(activeObj, players.Length);
            int id;

            BaseTank objectstate;
            SynchronizationMessage.Clear();
            for (int i = 0; i < tmpContainer.Length; i++)
            {
                GameObject[] g = tmpContainer[i];
                foreach (GameObject g1 in g)
                {
                    objectstate = g1.GetComponent <BaseTank>();
                    id          = objectstate.NetworkId;
                    byte FireState = objectstate.bullect;
                    if (id == -1)
                    {
                        enemycounter         += 1;
                        objectstate.NetworkId = enemycounter;
                        SynchronizationMessage.Add(g1.name + enemycounter, new SerializeUDP(objectstate.NetworkId, g1.transform.position, g1.transform));
                        // Debug.Log(g1.name + "-counter=" + enemycounter);
                    }
                    else
                    {
                        SynchronizationMessage.Add(g1.name + id, new SerializeUDP(id, g1.transform.position, g1.transform));
                    }

                    objectstate.bullect = 0;
                }
            }
        }
        syncbytes = ObjectToByteArray(SynchronizationMessage);

        return(syncbytes);
        // controlData[1] = c.whichBTN;
    }
Ejemplo n.º 4
0
    protected virtual void ProcessSynchronizationMessage(SynchronizationMessage msg)
    {
        GameState state;

        if (this.gameState.TryGetValue(msg.CurrentFrame, out state))
        {
            if (UFE.config.debugOptions.networkToggle)
            {
                debugger.enabled = true;
                debugger.text    = "";
                if (UFE.config.debugOptions.ping)
                {
                    debugger.text += "Ping:" + UFE.multiplayerAPI.GetLastPing() + " ms\n";
                }
                if (UFE.config.debugOptions.frameDelay)
                {
                    debugger.text += "Frame Delay:" + this.CalculateFrameDelay() + "\n";
                }
                if (UFE.config.debugOptions.currentLocalFrame)
                {
                    debugger.text += "Local Frame:" + UFE.currentNetworkFrame + "\n";
                }
                if (UFE.config.debugOptions.currentNetworkFrame)
                {
                    debugger.text += "Network Frame:" + msg.CurrentFrame + "\n";
                }
            }
            else
            {
                debugger.enabled = false;
            }

            //if (state.Equals(msg.Data)){
            if (Vector3.Distance(msg.Data.p1Position, state.p1Position) <= 0.1f)
            {
                //-----------------------------------------------------------------------------------------------------
                // If the game state received from the network message is equal to the stored state,
                // everything is ok, we can delete obsolete messages.
                //-----------------------------------------------------------------------------------------------------
//				Debug.Log(
//					"Synchroned!\tFrame = " + msg.CurrentFrame +
//					"\nExpected State: " + state +
//					"\nReceived State: " + msg.Data
//				);

                List <long> obsoleteNetworkFrames = new List <long>();
                foreach (long networkFrame in this.gameState.Keys)
                {
                    if (networkFrame <= msg.CurrentFrame)
                    {
                        obsoleteNetworkFrames.Add(msg.CurrentFrame);
                    }
                }

                for (int i = 0; i < obsoleteNetworkFrames.Count; ++i)
                {
                    this.gameState.Remove(obsoleteNetworkFrames[i]);
                }
            }
            else if (UFE.config.networkOptions.disconnectOnDesync)
            {
                //-----------------------------------------------------------------------------------------------------
                // Otherwise, a desynchronization has happened, so we should exit from the network game.
                //-----------------------------------------------------------------------------------------------------

                Debug.LogError(
                    "Synchronization Lost!\tFrame = " + msg.CurrentFrame +
                    "\nExpected State: " + state +
                    "\nReceived State: " + msg.Data
                    );

                if (UFE.multiplayerAPI.IsClient())
                {
                    UFE.multiplayerAPI.Disconnect();
                }
                else if (UFE.multiplayerAPI.IsServer())
                {
                    UFE.multiplayerAPI.StopServer();
                }
            }
        }
    }