Пример #1
0
    void OnGetSceneInfo(NetMsgDef msg)
    {
        TSCGetSceneInfo sceneInfo = TSCGetSceneInfo.ParseFrom(msg.mBtsData);

        for (int i = 0; i < sceneInfo.BuildingInfosCount; i++)
        {
            BuildingInfo info   = sceneInfo.BuildingInfosList[i];
            BUILDING     config = sanctuaryPackage.GetBuildingConfigDataByConfigID(info.ConfigId);
            //print(string.Format("{0}, {1}", config.BldgName, info.Number));
            sanctuaryPackage.AddBuilding(info);
        }
        userPackage.SetTotalContribution(sceneInfo.TotalContribution);
        for (int i = 0; i < sceneInfo.UserInfosCount; i++)
        {
            userPackage.AddUserInfo(sceneInfo.GetUserInfos(i));
            manors[i].SetUserID(sceneInfo.GetUserInfos(i).Uid);
            manors[i].gameObject.SetActive(true);
        }
        userPackage.SetGroupName(sceneInfo.GroupName);
        SendEvent("RefreshManorLevel");
        SendEvent("RefreshBuildingView");
        SendEvent("RefreshZombieSpawner");
        SendEvent("RefreshProduceBar");
        InitManor();
    }
Пример #2
0
    /// <summary>
    /// Create a group
    /// </summary>
    void OnCreateGroup(NetMsgDef msg)
    {
        TSCCreateGroup res = TSCCreateGroup.ParseFrom(msg.mBtsData);

        userPackage.SetGroupID(res.GroupId);
        LoadNextScene();
    }
Пример #3
0
    void OnGetPageList(NetMsgDef msg)
    {
        TSCGetPageList res = TSCGetPageList.ParseFrom(msg.mBtsData);

        mailPackage.SetMail(res);
        RefreshView();
    }
Пример #4
0
    void OnGetJoinGroupResult(NetMsgDef msg)
    {
        TSCApplyGroup res     = TSCApplyGroup.ParseFrom(msg.mBtsData);
        string        title   = "加入失败";
        string        content = "";

        if (!res.Exist)
        {
            FacadeSingleton.Instance.OverlayerPanel("UIMsgBoxPanel");
            NDictionary args = new NDictionary();
            content = "该ID不存在";
            args.Add("title", title);
            args.Add("content", content);
            SendEvent("OpenMsgBox", args);
            return;
        }
        if (res.Full)
        {
            FacadeSingleton.Instance.OverlayerPanel("UIMsgBoxPanel");
            NDictionary args = new NDictionary();
            content = "该庄园人员上限已满";
            args.Add("title", title);
            args.Add("content", content);
            SendEvent("OpenMsgBox", args);
            return;
        }
        UserPackage userPackage = FacadeSingleton.Instance.RetrieveData(ConstVal.Package_User) as UserPackage;

        userPackage.SetGroupID(res.GroupId);
        SceneLoader.LoadScene("SLoading");
    }
Пример #5
0
    void OnGetGroupRanking(NetMsgDef msg)
    {
        TSCGetGroupRanking res = TSCGetGroupRanking.ParseFrom(msg.mBtsData);

        dynamicPackage.SetGroupInfoList(res);
        ShowGroup();
    }
Пример #6
0
    void OnReceive(NetMsgDef msg)
    {
        TSCReceive receive    = TSCReceive.ParseFrom(msg.mBtsData);
        long       buildingID = receive.BuildingId;
        int        configID   = receive.ConfigId;
        int        num        = receive.Number;

        sanctuaryPackage.Receive(buildingID, receive);
        NBuildingInfo info = sanctuaryPackage.GetBuildingInfo(buildingID);

        if (sanctuaryPackage.GetBuildingFuncByConfigID(info.configID) == BuildingFunc.Craft)
        {
            SendEvent("RefreshCraftPanel");
        }
        NDictionary data = new NDictionary();

        if (configID == 0)   //elec
        {
            string content = string.Format("获得电力 x {0}", num);
            data.Add("content", content);
        }
        else
        {
            ITEM_RES itemConfig = itemPackage.GetItemDataByConfigID(configID);
            string   content    = string.Format("获得{0} x {1}", itemConfig.MinName, num);
            data.Add("content", content);
        }
        //info.number = Mathf.Max(0, info.number - num);
        //info.building.SetCollect(false);
        info.building.RefreshHud();
        FacadeSingleton.Instance.OpenUtilityPanel("UITipsPanel");
        FacadeSingleton.Instance.SendEvent("OpenTips", data);
        FacadeSingleton.Instance.InvokeService("RPCGetResourceInfo", ConstVal.Service_Sanctuary);
    }
Пример #7
0
 /// <summary>
 /// Try wrtiting to scoket from NetMsg queue
 /// </summary>
 void SendNetMsg()
 {
     if (mSendMsgQueue.Count < 1)
     {
         return;
     }
     mSendStream.Reset();
     lock (mSendMsgQueue)
     {
         while (mSendMsgQueue.Count >= 1)
         {
             NetMsgDef msg = mSendMsgQueue.Dequeue();
             if (msg == null)
             {
                 return;
             }
             if (!mSendStream.Write(msg))
             {
                 break;
             }
         }
     }
     if (mSendStream.WritePos > 0)
     {
         mOutStream.BeginWrite(mSendStream.Data, 0, (int)mSendStream.WritePos, OnWrite, null);
     }
 }
Пример #8
0
    /// <summary>
    /// Recieve Netmsg from socket & store to buffer
    /// </summary>
    void RecieveNetMsg(byte[] data, int size)
    {
        if (!mRecieveStream.Write(data, size))
        {
            Disconnect();
            return;
        }

        while (true)
        {
            NetMsgDef  msg  = null;
            NetMsgHead head = null;

            if (!mRecieveStream.Read(ref head))                         //Cant read msg head
            {
                break;
            }
            if (mRecieveStream.RemainReadCap < (uint)head.mSize - sizeof(short))        //Package is not completed, wait to next frame
            {
                //Restore ReadPos
                mRecieveStream.ShiftReadPos(-4);
                break;
            }
            byte[] btsData = new byte[head.mSize - sizeof(short)];
            if (!mRecieveStream.Read(btsData, head.mSize - sizeof(short)))
            {
                break;
            }
            msg = new NetMsgDef(head, btsData);
            lock (mRecieveMsgQueue)
            {
                mRecieveMsgQueue.Enqueue(msg);
            }
        }
    }
Пример #9
0
    void OnBuildingUpgrade(NetMsgDef msg)
    {
        TSCUpgrade upgrade = TSCUpgrade.ParseFrom(msg.mBtsData);

        if (!upgrade.IsState && upgrade.IsGroup && upgrade.IsResource && upgrade.IsProduction)
        {
            sanctuaryPackage.StartUpgrade(upgrade); FacadeSingleton.Instance.InvokeService("RPCGetResourceInfo", ConstVal.Service_Sanctuary);
        }
        else
        {
            NDictionary data = new NDictionary();
            data.Add("title", "升级失败");
            string content = "";
            if (upgrade.IsState)
            {
                content = "建筑正在升级中";
            }
            else if (!upgrade.IsGroup)
            {
                content = "庄园等级低于要求\n解锁/升级建筑以提升等级";
            }
            else if (!upgrade.IsResource)
            {
                content = "资源数量不足\n可至交易所中购买";
            }
            else if (!upgrade.IsProduction)
            {
                content = "其他建筑正在升级或解锁中";
            }
            data.Add("content", content);
            data.Add("method", 1);
            FacadeSingleton.Instance.OpenUtilityPanel("UIMsgBoxPanel");
            SendEvent("OpenMsgBox", data);
        }
    }
Пример #10
0
    void OnGetMessgeTag(NetMsgDef msg)
    {
        TSCGetMessageTag res = TSCGetMessageTag.ParseFrom(msg.mBtsData);

        mailPackage.SetUnreadMailCount(res.MessageNum);
        RefreshMailTag();
    }
Пример #11
0
    void OnGetUserStateRegular(NetMsgDef msg)
    {
        TSCGetUserStateRegular userState = TSCGetUserStateRegular.ParseFrom(msg.mBtsData);

        userPackage.SetPlayerState(userState);
        SendEvent("RefreshUserState");
    }
Пример #12
0
    void BuyItemResponce(NetMsgDef msg)
    {
        TSCBuyGoods res = TSCBuyGoods.ParseFrom(msg.mBtsData);
        string      content;

        if (res.IsChange)
        {
            content = "价格已改变, 请重新操作";
            FacadeSingleton.Instance.InvokeService("RPCGetItemTradeInfo", ConstVal.Service_Sanctuary);
        }
        else if (res.IsLimit)
        {
            content = "购买达到上限";
            FacadeSingleton.Instance.InvokeService("RPCGetPurchase", ConstVal.Service_Sanctuary);
        }
        else
        {
            ITEM_RES config = itemPackage.GetItemDataByConfigID(res.ConfigId);
            double   price  = itemPackage.GetItemPrice(res.ConfigId);
            content = string.Format("购买{0} x {1}单位\n消耗黄金{2}", config.MinName, res.Number, price * res.Number);
            FacadeSingleton.Instance.InvokeService("RPCGetPurchase", ConstVal.Service_Sanctuary);
            FacadeSingleton.Instance.InvokeService("RPCGetResourceInfo", ConstVal.Service_Sanctuary);
        }
        FacadeSingleton.Instance.OpenUtilityPanel("UIMsgBoxPanel");
        NDictionary args = new NDictionary();

        args.Add("content", content);
        args.Add("method", 1);
        SendEvent("OpenMsgBox", args);
    }
Пример #13
0
    void OnCancelCraft(NetMsgDef msg)
    {
        TSCInterruptProcess process = TSCInterruptProcess.ParseFrom(msg.mBtsData);

        sanctuaryPackage.CancelCraft(process.BuildingId);
        SendEvent("RefreshCraftPanel");
        FacadeSingleton.Instance.InvokeService("RPCGetResourceInfo", ConstVal.Service_Sanctuary);
    }
Пример #14
0
    /// <summary>
    /// Join a group
    /// </summary>
    void OnJoinGroup(NetMsgDef msg)
    {
        TSCApplyGroup res = TSCApplyGroup.ParseFrom(msg.mBtsData);

        if (!res.Exist || res.Full)
        {
            print("Group not exist or full");
        }
    }
Пример #15
0
    void OnGetResourceInfo(NetMsgDef msg)
    {
        TSCGetResourceInfo resInfos = TSCGetResourceInfo.ParseFrom(msg.mBtsData);

        itemPackage.SetResourceInfo(resInfos);
        SendEvent("RefreshUserState");
        SendEvent("RefreshItem");
        SendEvent("RefreshExmind");
    }
Пример #16
0
    void OnGetPageCount(NetMsgDef msg)
    {
        TSCGetPageCount res = TSCGetPageCount.ParseFrom(msg.mBtsData);

        maxIndex = res.PageCount;
        //countLabel.text = "x" + res.PageCount.ToString();
        indexLabel.text = curIndex.ToString() + "/" + maxIndex.ToString();
        GetPageList(1);
    }
Пример #17
0
    void OnGetWorldEvent(NetMsgDef msg)
    {
        TSCGetWorldEvent res          = TSCGetWorldEvent.ParseFrom(msg.mBtsData);
        EventPackage     eventPackage = FacadeSingleton.Instance.RetrieveData(ConstVal.Package_Event) as EventPackage;

        eventPackage.SetHistoryEvent(res);
        InitView();
        RefreshItemInfo();
    }
Пример #18
0
 public void OnResponceNetMsg(NetType nType, NetMsgDef msg)
 {
     if (msg.mMsgHead.mCmdID == -1)
     {
         ErrorResponce(msg);
         return;
     }
     print(string.Format("NetMsg Recieved cmdID:{0:D}, size:{1:D}", (int)msg.mMsgHead.mCmdID, (int)msg.mMsgHead.mSize));
     FacadeSingleton.Instance.InvokeRPCResponce(msg.mMsgHead.mCmdID, msg);
 }
Пример #19
0
 public bool Write(NetMsgDef msg)
 {
     if (!Write(msg.mMsgHead))
     {
         return(false);
     }
     if (!Write(msg.mBtsData, msg.mBtsData.Length))
     {
         return(false);
     }
     return(true);
 }
Пример #20
0
    void OnGetUserState(NetMsgDef msg)
    {
        TSCGetUserState userState = TSCGetUserState.ParseFrom(msg.mBtsData);

        userPackage.SetPlayerState(userState);
        SendEvent("RefreshUserState");
        if (initFlag == false)
        {
            BuildSanctuary();
            InitManor();
        }
    }
Пример #21
0
 public void InvokeRPCResponce(short cmdID, NetMsgDef msg)
 {
     if (cmdID < 1000)
     {
         return;
     }
     cmdID -= 1000;
     if (!mRPCResponceMap.ContainsKey(cmdID))
     {
         return;
     }
     mRPCResponceMap[cmdID](msg);
 }
Пример #22
0
    /// <summary>
    /// Send NetMsg, first store to list, then submit to client per frame
    /// </summary>
    public void SendNetMsg(NetType netType, short cmdID, byte[] data)
    {
        if (!networkMap.ContainsKey(netType))
        {
            return;
        }
        if (!msgBufferMap.ContainsKey(netType))
        {
            msgBufferMap.Add(netType, new List <NetMsgDef>());
        }
        Debug.Log(string.Format("Send Msg CMDID={0}", cmdID));
        NetMsgDef msg = RPCNetTools.CreateRpcMsg(cmdID, data);

        msgBufferMap[netType].Add(msg);
    }
Пример #23
0
    public bool Read(ref NetMsgDef msg)
    {
        msg = null;
        NetMsgHead head = null;

        if (!Read(ref head))
        {
            return(false);
        }
        byte[] btsData = new byte[head.mSize];
        if (!Read(btsData, head.mSize))
        {
            return(false);
        }
        msg = new NetMsgDef(head, btsData);
        return(true);
    }
Пример #24
0
    /// <summary>
    /// Throw NetMsg back to higer level, called per frame
    /// </summary>
    void HandleNetMsg()
    {
        if (mRecieveMsgQueue.Count < 1)
        {
            return;
        }
        int count = 20;      //handle 20 packages most per frame

        lock (mRecieveMsgQueue)
        {
            while (count-- > 0 && mRecieveMsgQueue.Count > 0)
            {
                NetMsgDef msg = mRecieveMsgQueue.Dequeue();
                if (msg == null)
                {
                    continue;
                }
                mResponceCallback(mNetType, msg);
            }
        }
    }
Пример #25
0
    void OnLoginSuccussed(NetMsgDef msg)
    {
        userPackage = FacadeSingleton.Instance.RetrieveData(ConstVal.Package_User) as UserPackage;
        PlayerPrefs.SetString("username", userName.value);
        TSCLogin login = TSCLogin.ParseFrom(msg.mBtsData);

        userPackage.SetUserID(login.Uid);
        GlobalFunction.GetTimeDelta(login.SystemCurrentTime);
        NetSingleton.Instance.StartHeartBeat();
        //check if need to create or join a sanctuary
        if (login.GroupId == 0)
        {
            //new player
            FacadeSingleton.Instance.OverlayerPanel("UISelectGroupPanel");
        }
        else
        {
            userPackage.SetGroupID(login.GroupId);
            LoadNextScene();
        }
    }
Пример #26
0
    void OnBuildingUnlock(NetMsgDef msg)
    {
        TSCUnlock unlock = TSCUnlock.ParseFrom(msg.mBtsData);

        if (unlock.IsGroup && unlock.IsResource && unlock.IsProduction && !unlock.IsState)
        {
            long     buildingID = unlock.BuildingId;
            long     finishTime = unlock.FinishTime;
            Building building   = sanctuaryPackage.GetSelectionBuilding();
            sanctuaryPackage.UnlockBuilding(buildingID, building, finishTime);
            building.RefreshView();
            FacadeSingleton.Instance.InvokeService("RPCGetResourceInfo", ConstVal.Service_Sanctuary);
        }
        else
        {
            NDictionary data = new NDictionary();
            data.Add("title", "解锁失败");
            string content = "";
            if (unlock.IsState)
            {
                content = "该建筑正在解锁中";
            }
            else if (!unlock.IsGroup)
            {
                content = "庄园等级低于要求\n解锁/升级以提升等级";
            }
            else if (!unlock.IsResource)
            {
                content = "资源数量不足\n可至交易所中购买";
            }
            else if (!unlock.IsProduction)
            {
                content = "其他建筑正在升级或解锁中";
            }
            data.Add("content", content);
            data.Add("method", 1);
            FacadeSingleton.Instance.OpenUtilityPanel("UIMsgBoxPanel");
            SendEvent("OpenMsgBox", data);
        }
    }
Пример #27
0
    void OnCraft(NetMsgDef msg)
    {
        TSCProcess process = TSCProcess.ParseFrom(msg.mBtsData);

        if (process.Uid != 0)
        {
            NDictionary data = new NDictionary();
            data.Add("content", string.Format("玩家{0}正在使用中", userPackage.GetUserInfo(process.Uid).name));
            data.Add("title", "加工失败");
            data.Add("method", 1);
            FacadeSingleton.Instance.OpenUtilityPanel("UIMsgBoxPanel");
            SendEvent("OpenMsgBox", data);
            return;
        }
        sanctuaryPackage.StartCraft(process);
        long remainTime = 0;

        if (GlobalFunction.GetRemainTime(process.FinishTime, out remainTime))
        {
            StartCoroutine(CraftTimer(process.BuildingId, remainTime));
            SendEvent("RefreshCraftPanel");
        }
        FacadeSingleton.Instance.InvokeService("RPCGetResourceInfo", ConstVal.Service_Sanctuary);
    }
Пример #28
0
 protected void InvokeRPCResponce(short cmdID, NetMsgDef msg)
 {
     FacadeSingleton.Instance.InvokeRPCResponce(cmdID, msg);
 }
Пример #29
0
 void OnGetGroupCount(NetMsgDef msg)
 {
     //TSCGetGroupPageCount res = TSCGetGroupPageCount.ParseFrom(msg.mBtsData);
     GetGroupRanking(1);
 }
Пример #30
0
    void OnGetLimit(NetMsgDef msg)
    {
        TSCGetPurchase res = TSCGetPurchase.ParseFrom(msg.mBtsData);

        itemPackage.SetBuyLimit(res);
    }