Beispiel #1
0
        public override void Process(UDPBox udpBox, byte[] packageBytes, IPEndPoint ipEndPoint)
        {
            mTemplate.Deserialize(packageBytes);

            switch (mTemplate.Op)
            {
            case RequestStringPackage.EOp.Request:

                var request = mTemplate.Content;
                UDPBox_GameThreadMediator.Instance.EnqueueToUpdateQueue(() =>
                {
                    var respText           = mOnProcessRequest(request);
                    mTemplate.RequestCache = request;
                    mTemplate.Content      = respText;
                    mTemplate.Op           = RequestStringPackage.EOp.Response;
                    udpBox.SendMessage(mTemplate.Serialize(), ipEndPoint);
                });

                break;

            case RequestStringPackage.EOp.Response:

                var content = mTemplate.Content;
                UDPBox_GameThreadMediator.Instance.EnqueueToUpdateQueue(() =>
                {
                    mOnProcessResponse(mTemplate.RequestCache, mTemplate.Content);
                });

                break;

            default:
                break;
            }
        }
Beispiel #2
0
        void FetchSelfTransforms(List <SyncGOTransforms_TransformMono> transformsList, UDPBox udpBox, IPEndPoint ipEndPoint, bool isFetchAll = false)
        {
            UDPBox_GameThreadMediator.Instance?.EnqueueToUpdateQueue(() =>
            {
                var package = new SyncGOTransformsPackage(mTemplate.HeadBytes);
                package.Op  = SyncGOTransformsPackage.EOperate.Push;

                for (int i = 0, iMax = transformsList.Count; i < iMax; i++)
                {
                    var transformMono = transformsList[i];
                    if (!transformMono.isSelfControl && !isFetchAll)
                    {
                        continue;
                    }

                    var transformInfo = new SyncGOTransformData();

                    transformInfo.NetworkID = transformMono.networkID;
                    transformInfo.Active    = transformMono.gameObject.activeSelf;
                    transformInfo.Pos_X     = transformMono.transform.position.x;
                    transformInfo.Pos_Y     = transformMono.transform.position.y;
                    transformInfo.Pos_Z     = transformMono.transform.position.z;
                    transformInfo.Euler_X   = transformMono.transform.eulerAngles.x;
                    transformInfo.Euler_Y   = transformMono.transform.eulerAngles.y;
                    transformInfo.Euler_Z   = transformMono.transform.eulerAngles.z;
                    transformInfo.SCALE_X   = transformMono.transform.localScale.x;
                    transformInfo.SCALE_Y   = transformMono.transform.localScale.y;
                    transformInfo.SCALE_Z   = transformMono.transform.localScale.z;

                    package.TransformList.Add(transformInfo);
                }

                udpBox.SendMessage(package.Serialize(), ipEndPoint);
            });
        }
Beispiel #3
0
        public override void Process(UDPBox udpBox, byte[] packageBytes, IPEndPoint ipEndPoint)
        {
            mTemplate.Deserialize(packageBytes);

            switch (mTemplate.Op)
            {
            case GetMasterClientCountPackage.EOperate.Get:
                mTemplate.ClientCount = mUdpBoxContainer.ClientIPConnectList.Count;
                mTemplate.Op          = GetMasterClientCountPackage.EOperate.Set;
                udpBox.SendMessage(mTemplate.Serialize(), ipEndPoint);
                break;

            case GetMasterClientCountPackage.EOperate.Set:
                ClientCount = mTemplate.ClientCount;
                break;

            default:
                break;
            }
        }
Beispiel #4
0
        public override void Process(UDPBox udpBox, byte[] packageBytes, IPEndPoint ipEndPoint)
        {
            mTemplate.Deserialize(packageBytes);

            switch (mTemplate.Op)
            {
            case RTT_TestPackage.EOp.A:

                mTemplate.BTime = DateTime.Now.Ticks;
                mTemplate.Op    = RTT_TestPackage.EOp.B;
                udpBox.SendMessage(mTemplate.Serialize(), ipEndPoint);

                break;

            case RTT_TestPackage.EOp.B:
                Debug.LogError("RTT: " + ((mTemplate.BTime - mTemplate.ATime) / (float)TimeSpan.TicksPerMillisecond) + " ms" + "   ipEndPoint: " + ipEndPoint);
                break;

            default:
                break;
            }
        }
Beispiel #5
0
        public override void Process(UDPBox udpBox, byte[] packageBytes, IPEndPoint ipEndPoint)
        {
            mTemplate.Deserialize(packageBytes);

            switch (mTemplate.Op)
            {
            case UserNameListPackage.EOperate.Push:

                var fetchedItem = mTemplate.UserNameInfoList[0];
                UpdateUserInfoList(fetchedItem);

                break;

            case UserNameListPackage.EOperate.Fetch:

                mTemplate.Op = UserNameListPackage.EOperate.Push;
                mTemplate.UserNameInfoList.Clear();
                mTemplate.UserNameInfoList.Add(new UserNameInfoData()
                {
                    IPAddress = mUDPBoxContainer.SelfIPAddress.ToString(),
                    BeginPort = mUDPBoxContainer.UdpBoxBeginPort,
                    EndPort   = mUDPBoxContainer.UdpBoxEndPort,
                    UserName  = SelfUserName,
                });
                udpBox.SendMessage(mTemplate.Serialize(), ipEndPoint);

                break;

            case UserNameListPackage.EOperate.FetchAll:

                mTemplate.Op = UserNameListPackage.EOperate.RestoreList;
                mTemplate.UserNameInfoList.Clear();
                for (int i = 0, iMax = UserNameInfoList.Count; i < iMax; i++)
                {
                    var item = UserNameInfoList[i];
                    mTemplate.UserNameInfoList.Add(new UserNameInfoData()
                    {
                        IPAddress = item.IPAddress,
                        BeginPort = item.BeginPort,
                        EndPort   = item.EndPort,
                        UserName  = item.UserName,
                    });
                }
                udpBox.SendMessage(mTemplate.Serialize(), ipEndPoint);

                break;

            case UserNameListPackage.EOperate.RestoreList:

                UserNameInfoList.Clear();
                for (int i = 0, iMax = mTemplate.UserNameInfoList.Count; i < iMax; i++)
                {
                    var item = mTemplate.UserNameInfoList[i];

                    UserNameInfoList.Add(new UserNameInfoData()
                    {
                        IPAddress = item.IPAddress,
                        BeginPort = item.BeginPort,
                        EndPort   = item.EndPort,
                        UserName  = item.UserName
                    });
                }

                break;

            default:
                break;
            }
        }