コード例 #1
0
    void OnMessage(IReadableBuffer data)
    {
        var msg = data.ReadString();

        AddTip(msg);
    }
コード例 #2
0
 public void Decode(IReadableBuffer br)
 {
     balance = br.ReadFloat();
 }
コード例 #3
0
ファイル: Room4Client.cs プロジェクト: radtek/SCM2
 // 逻辑帧前进
 void OnFrameMoveForwardMsg(IReadableBuffer data)
 {
     frameNoRecieved++;
     msgQ.Enqueue(new KeyValuePair <string, Action>("FrameEnd", null));
 }
コード例 #4
0
 // 不允许向 Net 组件发送网络消息
 public void OnMessage(string id, IReadableBuffer data, INetHelper s)
 {
     throw new Exception("Any message to Net component is invalid");
 }
コード例 #5
0
ファイル: PVPUI.cs プロジェクト: radtek/SCM2
    void OnBattleReady(IReadableBuffer data)
    {
        var infos = data.ReadArr <UserInfo>();

        BRUI.Show(infos);
    }
コード例 #6
0
 public void Decode(IReadableBuffer br)
 {
     this.mask.Decode(br);
     if (HasAiTmplId())
     {
         _aiTmplId = br.ReadShort();
     }
     if (HasHpMax())
     {
         _hpMax = br.ReadInt();
     }
     if (HasMpMax())
     {
         _mpMax = br.ReadInt();
     }
     if (HasPhyAtk())
     {
         _phyAtk = br.ReadInt();
     }
     if (HasPhyDef())
     {
         _phyDef = br.ReadInt();
     }
     if (HasMagAtk())
     {
         _magAtk = br.ReadInt();
     }
     if (HasMagDef())
     {
         _magDef = br.ReadInt();
     }
     if (HasAtkTimeLength())
     {
         _atkTimeLength = br.ReadFloat();
     }
     if (HasAtkKeyFrameTime())
     {
         _atkKeyFrameTime = br.ReadFloat();
     }
     if (HasStiffTime())
     {
         _stiffTime = br.ReadFloat();
     }
     if (HasFov())
     {
         _fov = br.ReadFloat();
     }
     if (HasAtkRange())
     {
         _atkRange = br.ReadFloat();
     }
     if (HasBodySize())
     {
         _bodySize = br.ReadFloat();
     }
     if (HasHit())
     {
         _hit = br.ReadInt();
     }
     if (HasDodge())
     {
         _dodge = br.ReadInt();
     }
     if (HasCrit())
     {
         _crit = br.ReadInt();
     }
     if (HasToughness())
     {
         _toughness = br.ReadInt();
     }
     if (HasMoveSpeed())
     {
         _moveSpeed = br.ReadShort();
     }
     if (HasAbilitiesData())
     {
         _abilitiesData = br.ReadArray <AbilityData>();
     }
     if (HasExtProps())
     {
         _extProps = br.ReadArray <UnitExtProp>();
     }
 }
コード例 #7
0
ファイル: AccountInfo.cs プロジェクト: orf53975/mana
 public void Decode(IReadableBuffer br)
 {
     username = br.ReadUTF8();
     password = br.ReadUTF8();
 }
コード例 #8
0
 void OnModifyUsrIntegrationCost(Session s, IReadableBuffer data)
 {
     s.Usr.Info.IntegrationCost = data.ReadInt();
     s.Usr.Update();
 }
コード例 #9
0
ファイル: BufferExtension.cs プロジェクト: orf53975/mana
 public static short ReadShort(this IReadableBuffer br)
 {
     return((short)br.ReadInt16());
 }
コード例 #10
0
 void OnModifyUsrCurAvatar(Session s, IReadableBuffer data)
 {
     s.Usr.Info.CurAvator = data.ReadString();
     s.Usr.Update();
 }
コード例 #11
0
 void OnModifyUsrName(Session s, IReadableBuffer data)
 {
     s.Usr.Info.Name = data.ReadString();
     s.Usr.Update();
 }
コード例 #12
0
ファイル: MathEx.cs プロジェクト: moto2002/Avocat
 public static Fix64 ReadFix64(this IReadableBuffer data)
 {
     return(Fix64.FromRaw(data.ReadLong()));
 }
コード例 #13
0
ファイル: UnitInfo.cs プロジェクト: orf53975/mana
 public void Decode(IReadableBuffer br)
 {
     this.mask.Decode(br);
     if (HasPlayerId())
     {
         _playerId = br.ReadInt();
     }
     if (HasUid())
     {
         _uid = br.ReadInt();
     }
     if (HasName())
     {
         _name = br.ReadUTF8();
     }
     if (HasAppearance())
     {
         _appearance = br.ReadUTF8();
     }
     if (HasCategory())
     {
         _category = br.ReadByte();
     }
     if (HasType())
     {
         _type = br.ReadByte();
     }
     if (HasCamp())
     {
         _camp = br.ReadByte();
     }
     if (HasLev())
     {
         _lev = br.ReadShort();
     }
     if (HasX())
     {
         _x = br.ReadFloat();
     }
     if (HasY())
     {
         _y = br.ReadFloat();
     }
     if (HasZ())
     {
         _z = br.ReadFloat();
     }
     if (HasFaceTo())
     {
         _faceTo = br.ReadFloat();
     }
     if (HasHpPercent())
     {
         _hpPercent = br.ReadFloat();
     }
     if (HasMpPercent())
     {
         _mpPercent = br.ReadFloat();
     }
     if (HasMoveSpeed())
     {
         _moveSpeed = br.ReadShort();
     }
     if (HasActionState())
     {
         _actionState = br.ReadByte();
     }
     if (HasCurrentAnim())
     {
         _currentAnim = br.ReadInt();
     }
     if (HasEffectShow())
     {
         _effectShow = br.ReadInt();
     }
     if (HasControlFlag())
     {
         _controlFlag = br.ReadInt();
     }
     if (HasBuffsData())
     {
         _buffsData = br.ReadArray <BuffData>();
     }
 }
コード例 #14
0
ファイル: Result.cs プロジェクト: orf53975/mana
 public void Decode(IReadableBuffer br)
 {
     code = (Code)br.ReadInt();
     info = br.ReadUTF8();
 }
コード例 #15
0
ファイル: Heartbeat.cs プロジェクト: orf53975/mana
 public void Decode(IReadableBuffer br)
 {
     timestamp = br.ReadInt();
 }
コード例 #16
0
ファイル: BufferExtension.cs プロジェクト: orf53975/mana
 public static ushort ReadUnsignedShort(this IReadableBuffer br)
 {
     return((ushort)br.ReadInt16());
 }
コード例 #17
0
        // 时间驱动处理所有已经接收到的网络消息,并分发到其它各个组件对象
        public void OnTimeElapsed(int te)
        {
            // 每帧发送一次网络数据
            p.ProcessDoSend();

            // 处理所有未完成的连接操作
            p.ProcessPendingConnecting();

            // 处理所有网络消息
            NetConnection[] connections = p.AllConnections;
            foreach (NetConnection nc in connections)
            {
                IReadableBuffer data = nc.ReceivedData;

                // 处理已经完整接收的部分
                while (true)
                {
                    // 判断消息是否已经完整接收
                    if (data.Available < sizeof(int))
                    {
                        break;
                    }

                    int len = 0;
                    if (!data.PeekInt(ref len))
                    {
                        break;
                    }

                    if (len < 0 || len > NetConnection.MaxRecieveBufferSize)
                    {
                        string ex = "invalid message length: " + len;
                        nc.Close(ex);
                        throw new Exception(ex);
                        // break;
                    }

                    if (data.Available < len + sizeof(int))
                    {
                        break;
                    }
                    else
                    {
                        data.Skip(sizeof(int));
                    }

                    Connection connWrap = GetConnectionWrap(nc);

                    // 对该条消息解密
                    data.TravelReplaceBytes4Read(0, len, (byte d) => { return(connWrap.Decrypt(d)); });

                    if (OnMessageRecieved != null)
                    {
                        OnMessageRecieved();
                    }

                    // 消息序号,正数为普通消息,负数为应答消息
                    long no = data.ReadLong();

                    if (no > 0)
                    {
                        helper.responseID = -no;
                        string       componentName = data.ReadString();
                        NetComponent c             = GetComponent(componentName) as NetComponent;
                        byte[]       msgData       = data.ReadBytes(len - sizeof(long) - sizeof(int) - componentName.Length);

                        // 没找到对应的模块则忽略
                        if (c == null)
                        {
                            string ex = "no such a component named: " + componentName;
                            nc.Close(ex);
                            throw new Exception(ex);
                            // break;
                        }

                        // 投递消息
                        RingBuffer msgBody = new RingBuffer(true, true);
                        msgBody.Write(msgData, 0, msgData.Length);
                        c.OnMessage(connWrap, msgBody);
                    }
                    else if (no < 0)
                    {
                        byte[]     msgData = data.ReadBytes(len - sizeof(long));
                        RingBuffer msgBody = new RingBuffer(true, true);
                        msgBody.Write(msgData, 0, msgData.Length);

                        // 投递消息
                        CallbackNode tcb;
                        if (callbacks.TryGetValue(no, out tcb))
                        {
                            Action <IReadableBuffer> cb = tcb.cb;
                            callbacks.Remove(no);
                            usrDefinedExpireProcess.Remove(no);

                            if (cb != null)
                            {
                                cb(msgBody);
                            }
                        }
                        else
                        {
                            string ex = "no request callback for " + no;
                            nc.Close(ex);
                            throw new Exception(ex);
                            // break;
                        }
                    }
                    else
                    {
                        string ex = "0 is an invalid message sequence number";
                        nc.Close(ex);
                        throw new Exception(ex);
                        // break;
                    }
                }
            }

            // 检查请求超时
            CheckNextCallbackTimeout();
        }
コード例 #18
0
ファイル: BufferExtension.cs プロジェクト: orf53975/mana
 public static int ReadInt(this IReadableBuffer br)
 {
     return(br.ReadInt32());
 }
コード例 #19
0
        private void DeserializeReplayMag(DataAnalysisInfo info, IReadableBuffer buff)
        {
            var player = buff.ReadInt();
            var type   = buff.ReadString();

            switch (type)
            {
            case "Dog":
                if (player == 1)
                {
                    info.DogCount1++;
                }
                else if (player == 2)
                {
                    info.DogCount2++;
                }
                break;

            case "Soldier":
                if (player == 1)
                {
                    info.SoldierCount1++;
                }
                else if (player == 2)
                {
                    info.SoldierCount2++;
                }
                break;

            case "Firebat":
                if (player == 1)
                {
                    info.FirebatCount1++;
                }
                else if (player == 2)
                {
                    info.FirebatCount2++;
                }
                break;

            case "MagSpider":
                if (player == 1)
                {
                    info.MagSpiderCount1++;
                }
                else if (player == 2)
                {
                    info.MagSpiderCount2++;
                }
                break;

            case "Robot":
                if (player == 1)
                {
                    info.RobotCount1++;
                }
                else if (player == 2)
                {
                    info.RobotCount2++;
                }
                break;

            case "Tank":
                if (player == 1)
                {
                    info.TankCount1++;
                }
                else if (player == 2)
                {
                    info.TankCount2++;
                }
                break;

            case "Thor":
                if (player == 1)
                {
                    info.ThorCount1++;
                }
                else if (player == 2)
                {
                    info.ThorCount2++;
                }
                break;

            case "Hammer":
                if (player == 1)
                {
                    info.HammerCount1++;
                }
                else if (player == 2)
                {
                    info.HammerCount2++;
                }
                break;

            case "Warplane":
                if (player == 1)
                {
                    info.WarplaneCount1++;
                }
                else if (player == 2)
                {
                    info.WarplaneCount2++;
                }
                break;

            case "MotherShip":
                if (player == 1)
                {
                    info.MotherShipCount1++;
                }
                else if (player == 2)
                {
                    info.MotherShipCount2++;
                }
                break;
            }
        }
コード例 #20
0
ファイル: BufferExtension.cs プロジェクト: orf53975/mana
 public static long ReadLong(this IReadableBuffer br)
 {
     return(br.ReadInt64());
 }
コード例 #21
0
ファイル: UnitUtils.cs プロジェクト: radtek/SCM2
        public static UnitConfigInfo ReadUnitInfo(IReadableBuffer reader)
        {
            var info = new UnitConfigInfo();

            info.DisplayName      = reader.ReadString();
            info.Cost             = reader.ReadInt();
            info.GasCost          = reader.ReadInt();
            info.ConstructingTime = reader.ReadFix64();
            info.MaxNum           = reader.ReadInt();
            info.MaxVelocity      = reader.ReadFix64();
            info.IsBuilding       = reader.ReadBool();
            info.IsBiological     = reader.ReadBool();
            info.IsMechanical     = reader.ReadBool();
            info.IsAirUnit        = reader.ReadBool();
            info.UnAttackable     = reader.ReadBool();
            info.VisionRadius     = reader.ReadFix64();
            info.ChaseRadius      = reader.ReadFix64();
            info.Suppliment       = reader.ReadFix64();
            info.AITypes          = reader.ReadStringArr();

            if (reader.ReadBool())
            {
                var len2 = reader.ReadInt();
                info.AIParams = new Fix64[len2][];
                for (var i = 0; i < len2; i++)
                {
                    if (reader.ReadBool())
                    {
                        var len = reader.ReadInt();
                        info.AIParams[i] = new Fix64[len];
                        for (var j = 0; j < len; j++)
                        {
                            info.AIParams[i][j] = reader.ReadFix64();
                        }
                    }
                }
            }

            info.SizeRadius      = reader.ReadInt();
            info.NoBody          = reader.ReadBool();
            info.NoCard          = reader.ReadBool();
            info.MaxHp           = reader.ReadInt();
            info.CanAttackGround = reader.ReadBool();
            info.CanAttackAir    = reader.ReadBool();

            info.AttackType  = reader.ReadStringArr();
            info.AttackRange = reader.ReadIntArr();
            info.AttackPower = reader.ReadIntArr();

            if (reader.ReadBool())
            {
                var len6 = reader.ReadInt();
                info.AttackInterval = new Fix64[len6];

                for (var i = 0; i < len6; i++)
                {
                    info.AttackInterval[i] = reader.ReadFix64();
                }
            }

            info.AOEType = reader.ReadStringArr();

            if (reader.ReadBool())
            {
                var len8 = reader.ReadInt();
                info.AOEParams = new Fix64[len8][];
                for (var i = 0; i < len8; i++)
                {
                    if (reader.ReadBool())
                    {
                        var len = reader.ReadInt();
                        info.AOEParams [i] = new Fix64[len];
                        for (var j = 0; j < len; j++)
                        {
                            info.AOEParams[i][j] = reader.ReadFix64();
                        }
                    }
                }
            }

            info.ArmorType = reader.ReadString();
            info.Defence   = reader.ReadInt();

            if (reader.ReadBool())
            {
                var len9 = reader.ReadInt();
                info.Prerequisites = new string[len9][];
                for (var i = 0; i < len9; i++)
                {
                    if (reader.ReadBool())
                    {
                        var len = reader.ReadInt();
                        info.Prerequisites[i] = new string[len];
                        for (var j = 0; j < len; j++)
                        {
                            info.Prerequisites [i] [j] = reader.ReadString();
                        }
                    }
                }
            }

            info.ReconstructTo   = reader.ReadStringArr();
            info.ReconstructFrom = reader.ReadString();
            info.TechLevel       = reader.ReadInt();
            info.Desc            = reader.ReadString();
            info.InVisible       = reader.ReadBool();
            info.IsObserver      = reader.ReadBool();
            info.ReboundDamage   = reader.ReadFix64();
            info.Pets            = reader.ReadStringArr();
            info.OriginalType    = reader.ReadString();
            info.IsThirdType     = reader.ReadBool();

            return(info);
        }
コード例 #22
0
ファイル: BufferExtension.cs プロジェクト: orf53975/mana
        public static float ReadFloat(this IReadableBuffer br)
        {
            var value = br.ReadInt32();

            return(CodingUtil.DecodeFloat32(value));
        }
コード例 #23
0
        // 时间驱动处理所有已经接收到的网络消息,并分发到其它各个组件对象
        public void OnTimeElapsed(int te)
        {
            // 每帧发送一次网络数据
            p.ProcessDoSend();

            // 处理所有未完成的连接操作
            p.ProcessPendingConnecting();

            // 处理所有网络消息
            NetConnection[] connections = p.AllConnections;
            foreach (NetConnection nc in connections)
            {
                IReadableBuffer data = nc.ReceivedData;

                // 处理已经完整接收的部分
                while (true)
                {
                    // 判断是否接收到重复上一条消息的指示头
                    if (data.Available < sizeof(bool))
                    {
                        break;
                    }

                    var repeatLastOne = false;
                    if (!data.PeekBool(ref repeatLastOne))
                    {
                        break;
                    }

                    Connection connWrap = GetConnectionWrap(nc);

                    if (repeatLastOne)
                    {
                        data.Skip(sizeof(bool));
                        var componentName = nc.LastData2Component;
                        if (componentName == null)
                        {
                            LogWarning("componentName repeated is null");
                            LogWarning("connected: " + nc.IsConnected + " : " + ((IPEndPoint)nc.Socket.RemoteEndPoint).Address.ToString());
                            nc.Close("componentName repeated is null");
                            break;
                        }

                        var          msgBody = new RingBuffer(true, true);
                        NetComponent c       = GetCom(componentName) as NetComponent;
                        msgBody.Write(nc.LastGetData, 0, nc.LastGetData.Length);
                        c.OnMessage(connWrap, msgBody);
                    }
                    else
                    {
                        // 判断消息是否已经完整接收
                        if (data.Available < sizeof(bool) + sizeof(int))
                        {
                            break;
                        }

                        int len = 0;
                        if (!data.PeekInt(sizeof(bool), ref len))
                        {
                            break;
                        }

                        if (len < 0 || len > NetConnection.MaxRecieveBufferSize)
                        {
                            string ex = "invalid message length: " + len;
                            nc.Close(ex);
                            throw new Exception(ex);
                            // break;
                        }

                        if (data.Available < len + sizeof(bool) + sizeof(int))
                        {
                            break;
                        }

                        data.Skip(sizeof(bool));
                        data.Skip(sizeof(int));

                        // 对该条消息解密
                        data.TravelReplaceBytes4Read(0, len, (byte d) => { return(connWrap.Decrypt(d)); });

                        if (OnMessageRecieved != null)
                        {
                            OnMessageRecieved();
                        }

                        // 消息序号,正数为普通消息,负数为应答消息
                        bool hasNo  = data.ReadBool();
                        long no     = hasNo ? data.ReadLong() : 0;
                        int  offset = hasNo ? sizeof(long) + sizeof(bool) : sizeof(bool);

                        if (no >= 0)
                        {
                            helper.responseID = -no;
                            string componentName = data.ReadString();
                            if (componentName == null)
                            {
                                throw new Exception("componentName try to get is null");
                            }
                            NetComponent c       = GetCom(componentName) as NetComponent;
                            byte[]       msgData = data.ReadBytes(len - offset - sizeof(int) - componentName.Length);

                            nc.LastGetData        = msgData;
                            nc.LastData2Component = componentName;

                            // 没找到对应的模块则忽略
                            if (c == null)
                            {
                                string ex = "no such a component named: " + componentName;
                                nc.Close(ex);
                                throw new Exception(ex);
                                // break;
                            }

                            // 投递消息
                            var msgBody = new RingBuffer(true, true);
                            msgBody.Write(msgData, 0, msgData.Length);
                            c.OnMessage(connWrap, msgBody);
                        }
                        else
                        {
                            byte[] msgData = data.ReadBytes(len - offset);
                            var    msgBody = new RingBuffer(true, true);
                            msgBody.Write(msgData, 0, msgData.Length);

                            // 投递消息
                            CallbackNode tcb;
                            if (callbacks.TryGetValue(no, out tcb))
                            {
                                Action <IReadableBuffer> cb = tcb.cb;
                                callbacks.Remove(no);
                                usrDefinedExpireProcess.Remove(no);

                                if (cb != null)
                                {
                                    cb(msgBody);
                                }
                            }
                            else
                            {
                                string ex = "no request callback for " + no;
                                nc.Close(ex);
                                throw new Exception(ex);
                                // break;
                            }
                        }
                    }
                }
            }

            // 检查请求超时
            CheckNextCallbackTimeout();
        }
コード例 #24
0
ファイル: BufferExtension.cs プロジェクト: orf53975/mana
        public static float ReadFloat16(this IReadableBuffer br)
        {
            var v = (short)br.ReadInt16();

            return(CodingUtil.DecodeFloat16(v));
        }
コード例 #25
0
        // 从匹配列表移除
        void OnCancel(Session s, IReadableBuffer data, IWriteableBuffer buff)
        {
            bool isSuccess = waitingList.Remove(s.ID);

            buff.Write(isSuccess);
        }
コード例 #26
0
ファイル: BufferExtension.cs プロジェクト: orf53975/mana
 public static bool ReadBoolean(this IReadableBuffer br)
 {
     return(br.ReadByte() != 0);
 }
コード例 #27
0
        // 用户登录请求
        void OnUserLoginMsg(Connection conn, IReadableBuffer data, IWriteableBuffer buff, Action end)
        {
            var uid = data.ReadString();

            var deviceModel = "";

            // 检查版本

            var isNewVersion = false;
            var version      = "";
            var buildNo      = "";
            var platform     = "";

            if (data.Available != 0)
            {
                version  = data.ReadString();
                platform = data.ReadString();
            }

            if (data.Available != 0)
            {
                deviceModel = data.ReadString();
                buildNo     = data.ReadString();
            }

            isNewVersion = (version == SrvVersion) && (buildNo == SrvBuildNo);

            buff.Write(isNewVersion);
            if (!isNewVersion)
            {
                if (platform == "IOS")
                {
                    buff.Write("https://www.apple.com");
                }
                else if (platform == "ANDROID")
                {
                    buff.Write("https://www.google.com");
                }
                else
                {
                    buff.Write("https://www.baidu.com");
                }

                end();
                return;
            }

            UC.Retrieve(uid, (usr) =>
            {
                if (SC[uid] != null)
                {
                    KickOut(uid);
                    end();
                    return;
                }

                var isNew = usr == null;
                if (isNew) // 用户不存在就创建新的
                {
                    usr                  = new User();
                    usr.ID               = uid;
                    usr.Info             = new UserInfo();
                    usr.Info.DeviceModel = deviceModel;
                    UC.AddNew(usr);

                    UserManager.SetDefaultInfo(usr);
                }

                // 创建会话
                var s   = new Session();
                s.Usr   = usr;
                s.Conn  = conn;
                SC[uid] = s;

                // 登录日志
                SrvLogger.Log(new LoginInfo(uid, usr.Info.Name, conn.GetIP(), isNew));

                BeforeUserLogin.SC(s, isNew);

                // 通知登录成功
                buff.Write(true);
                buff.Write(usr.Info);

                // 问卷调查

                var totalCount = usr.Info.WinCount + usr.Info.LoseCount;
                if (totalCount >= 1 && totalCount < 5)
                {
                    buff.Write("1");
                    end();
                    OnUserLogin.SC(s, isNew);
                }
                else if (totalCount >= 5)
                {
                    QRC.Retrieve("1" + s.Usr.ID, (questionnaire) =>
                    {
                        if (questionnaire == null)
                        {
                            buff.Write("1");
                            end();
                            OnUserLogin.SC(s, isNew);
                        }
                        else
                        {
                            buff.Write("2");
                            end();
                            OnUserLogin.SC(s, isNew);
                        }
                    });
                }
                else
                {
                    buff.Write("0");
                    end();
                    OnUserLogin.SC(s, isNew);
                }
            });
        }
コード例 #28
0
 // 响应网络消息
 public virtual void OnMessage(Connection conn, IReadableBuffer data)
 {
 }
コード例 #29
0
ファイル: Room4Client.cs プロジェクト: radtek/SCM2
    // 异常报错
    void OnCrashMsg(IReadableBuffer data)
    {
        var exMsg = data.ReadString();

        UIManager.Instance.Tips.AddErrorMsg("战斗报错:" + exMsg);
    }
コード例 #30
0
ファイル: SerializableData.cs プロジェクト: Luxg520/L01
 public override void Deserialize(IReadableBuffer data)
 {
     UniqueID = data.ReadULong();
     TID      = data.ReadInt();
     base.Deserialize(data);
 }