Example #1
0
        public virtual void JoinRoom(KcpUser linker)
        {
            if (linker.userInfo == null)
            {
                return;
            }
            for (int i = 0; i < 3; i++)
            {
                var user = gamers[i].userInfo;
                if (user == null)
                {
                    user =
                        gamers[i].userInfo = linker.userInfo;
                    gamers[i].linker       = linker;
                    DataBuffer db   = new DataBuffer();
                    var        fake = new FakeStruct(db, Req.Length);
                    fake[Req.Cmd]  = RpcCmd.JoinRoom;
                    fake[Req.Type] = MessageType.Rpc;

                    FakeStruct gamerInfo = new FakeStruct(db, 3);
                    //gamerInfo[0] = i;//seat
                    //gamerInfo[1] = user.id;//uid
                    //gamerInfo[2] = RoomId;//roomid
                    fake.SetData(Req.Args, gamerInfo);
                    db.fakeStruct = fake;

                    Broadcast(db);
                    GetRoomDetail(linker);
                    user.RoomId = RoomId;
                    break;
                }
            }
        }
Example #2
0
        void StartCountdown()
        {
            Countdown--;
            if (Countdown <= 0)
            {
                RoomState = State_HairCards;
                Countdown = 10;
                landlord.ReStart();
                for (int i = 0; i < 3; i++)
                {
                    var cards = landlord.GamerCards[i];
                    gamers[i].Cards = new List <int>(cards);
                    var linker = gamers[i].linker;
                    if (linker != null)
                    {
                        DataBuffer db   = new DataBuffer();
                        var        fake = new FakeStruct(db, Req.Length);
                        fake[Req.Cmd]  = RpcCmd.HairCards;
                        fake[Req.Type] = MessageType.Rpc;
                        fake.SetData(Req.Args, cards);
                        db.fakeStruct = fake;

                        //linker.Send(AES.Instance.Encrypt(db.ToBytes()), EnvelopeType.AesDataBuffer);
                    }
                }
            }
            else
            {
                BroadcastCountdown();
            }
        }
Example #3
0
        static void QueryRoom(KcpUser linker, DataBuffer buffer)
        {
            var list = RoomManager.QueryFreeRoom();

            if (list.Count == 0)
            {
                ErrorCode.SendErrorCode(linker, ErrorCode.NoFreeRoom);
                return;
            }
            DataBuffer db   = new DataBuffer();
            FakeStruct fake = new FakeStruct(db, Req.Length);

            fake[Req.Cmd]  = QueryCmd.QueryRoom;
            fake[Req.Type] = MessageType.Query;
            db.fakeStruct  = fake;
            int             c     = list.Count;
            FakeStructArray array = new FakeStructArray(db, 3, c);

            for (int i = 0; i < c; i++)
            {
                var room = list[i];
                array[c, 0] = room.RoomId;
                array[c, 1] = room.Number;
                array.SetData(c, 2, room.Name);
            }
            fake.SetData(Req.Args, array);
            linker.Send(AES.Instance.Encrypt(db.ToBytes()), EnvelopeType.AesDataBuffer);
        }
Example #4
0
        /// <summary>
        /// 储存数据布局信息
        /// </summary>
        /// <param name="db">缓存实例</param>
        /// <returns></returns>
        public FakeStruct SaveToDataBuffer(DataBuffer db)
        {
            FakeStruct      fake = new FakeStruct(db, 2);
            FakeStructArray fsa  = new FakeStructArray(db, 12, lines.Count);

            for (int i = 0; i < lines.Count; i++)
            {
                lines[i].SaveToDataBuffer(fsa, i);
            }
            fake.SetData(0, fsa);
            fsa = new FakeStructArray(db, 4, areas.Count);
            for (int i = 0; i < areas.Count; i++)
            {
                areas[i].SaveToDataBuffer(fsa, i);
            }
            fake.SetData(1, fsa);
            return(fake);
        }
    public static void CreateMapInfo(UnityEngine.Object[] sprites, string savepath)
    {
        CharInfoA[] tmp = new CharInfoA[16];
        for (int i = 0; i < 16; i++)
        {
            tmp[i]     = new CharInfoA();
            tmp[i].len = i + 1;
        }
        CharUV uv = new CharUV();

        unsafe
        {
            fixed(byte *bp = &buff[0])
            {
                for (int i = 0; i < sprites.Length; i++)
                {
                    var sp = sprites[i] as Sprite;
                    if (sp != null)
                    {
                        int   len = AddSpriteInfo(sp);
                        var   dat = tmp[len - 1].dat;
                        char *cp  = (char *)bp;
                        for (int j = 0; j < len; j++)
                        {
                            dat.Add(*cp);
                            cp++;
                        }
                        CalculUV(sp.rect, sp.texture.width, sp.texture.height, ref uv);
                        tmp[len - 1].uvs.Add(uv);
                    }
                }
            }
        }
        DataBuffer db   = new DataBuffer();
        FakeStruct fake = new FakeStruct(db, 16);

        for (int i = 0; i < 16; i++)
        {
            var        t  = tmp[i];
            FakeStruct fs = new FakeStruct(db, 3);
            fs[0] = t.len;
            if (tmp[i].dat.Count > 0)
            {
                fs[1] = db.AddArray <char>(t.dat.ToArray());
                fs[2] = db.AddArray <CharUV>(t.uvs.ToArray());
            }
            fake.SetData(i, fs);
        }
        db.fakeStruct = fake;
        byte[] data = db.ToBytes();
        File.WriteAllBytes(savepath, data);
        Debug.Log("emoji info create done");
    }
        public void SendString(Int32 cmd, Int32 type, string obj)
        {
            DataBuffer db   = new DataBuffer(4);
            var        fake = new FakeStruct(db, Req.Length);

            fake[Req.Cmd]  = cmd;
            fake[Req.Type] = type;
            db.fakeStruct  = fake;
            fake.SetData(Req.Args, obj);
            var dat = db.ToBytes();

            byte[] buf = new byte[dat.Length];
            int    len = LZ4Codec.Encode32Unsafe(dat, 0, dat.Length, buf, 0, buf.Length);

            dat = WriteLen(dat.Length, len, buf);
            buf = AES.Instance.Encrypt(dat);
            link.Send(buf, EnvelopeType.AesDataBuffer);
        }
Example #7
0
    public static unsafe byte[] PackStruct <T>(Int32 cmd, Int32 type, T obj) where T : unmanaged
    {
        DataBuffer db   = new DataBuffer(4);
        var        fake = new FakeStruct(db, Req.Length);

        fake[Req.Cmd]  = cmd;
        fake[Req.Type] = type;
        db.fakeStruct  = fake;
        int        len = sizeof(T);
        FakeStruct fs  = new FakeStruct(db, len / 4);

        *(T *)fs.ip = obj;
        fake.SetData(Req.Args, fs);
        var dat = db.ToBytes();

        byte[] buf = new byte[dat.Length];
        len = LZ4Codec.Encode32Unsafe(dat, 0, dat.Length, buf, 0, buf.Length);
        dat = WriteLen(dat.Length, len, buf);
        buf = AES.Instance.Encrypt(dat);
        return(buf);
    }
Example #8
0
    public static byte[] PackObject <T>(Int32 cmd, Int32 type, object obj) where T : class
    {
        DataBuffer db   = new DataBuffer(4);
        var        fake = new FakeStruct(db, Req.Length);

        fake[Req.Cmd]  = cmd;
        fake[Req.Type] = type;
        db.fakeStruct  = fake;
        var          ser = MessagePackSerializer.Get <T>();
        MemoryStream ms  = new MemoryStream();

        ser.Pack(ms, obj);
        fake.SetData(Req.Args, ms.ToArray());
        ms.Dispose();
        var dat = db.ToBytes();

        byte[] buf = new byte[dat.Length];
        int    len = LZ4Codec.Encode32Unsafe(dat, 0, dat.Length, buf, 0, buf.Length);

        dat = WriteLen(dat.Length, len, buf);
        buf = AES.Instance.Encrypt(dat);
        return(buf);
    }
    static void GetAllServerIp(KcpUser linker, DataBuffer data)
    {
        int index = data.fakeStruct[Req.Args];
        var info  = ServerTable.GetAllServer();
        int c     = info.Count;

        if (c > 0)
        {
            DataBuffer db   = new DataBuffer();
            FakeStruct fake = new FakeStruct(db, Req.Length);
            fake[Req.Cmd]  = ProCmd.AllServer;
            fake[Req.Type] = MessageType.Pro;
            FakeStructArray array = new FakeStructArray(db, 3, c);
            for (int i = 0; i < c; i++)
            {
                array[i, 0] = info[i].ip;
                array[i, 1] = info[i].port;
                array.SetData(i, 2, info[i].name);
            }
            fake.SetData(Req.Args, array);
            db.fakeStruct = fake;
            linker.Send(AES.Instance.Encrypt(db.ToBytes()), EnvelopeType.AesDataBuffer);
        }
    }
Example #10
0
        public void Reconnect(KcpUser linker)
        {
            if (linker.userInfo == null)
            {
                return;
            }
            var uid = linker.userInfo.id;

            for (int i = 0; i < 3; i++)
            {
                var user = gamers[i].userInfo;
                if (user == null)
                {
                    if (user.id == uid)
                    {
                        gamers[i].userInfo = linker.userInfo;
                        gamers[i].linker   = linker;
                        DataBuffer db   = new DataBuffer();
                        var        fake = new FakeStruct(db, Req.Length);
                        fake[Req.Cmd]  = RpcCmd.JoinRoom;
                        fake[Req.Type] = MessageType.Rpc;

                        FakeStruct gamerInfo = new FakeStruct(db, 3);
                        //gamerInfo[0] = i;//seat
                        //gamerInfo[1] = user.id;//uid
                        //gamerInfo[2] = RoomId;//roomid
                        fake.SetData(Req.Args, gamerInfo);
                        db.fakeStruct = fake;

                        linker.Send(AES.Instance.Encrypt(db.ToBytes()), EnvelopeType.AesDataBuffer);
                        GetRoomDetail(linker);
                        break;
                    }
                }
            }
        }
Example #11
0
        public void GetRoomDetail(KcpUser linker)
        {
            DataBuffer data = new DataBuffer();
            var        fake = new FakeStruct(data, Req.Length);

            fake[Req.Cmd]  = RpcCmd.RoomDetail;
            fake[Req.Type] = MessageType.Rpc;

            FakeStructArray gs = new FakeStructArray(data, 3, 3);

            for (int i = 0; i < 3; i++)
            {
                var user = gamers[i].userInfo;
                if (user != null)
                {
                    //gs[i, 0] = user.id;
                    //gs[i, 1] = 1000;//金币
                    //gs[i, 2] = gamers[i].ready;
                }
            }
            fake.SetData(Req.Args, gs);
            data.fakeStruct = fake;
            linker.Send(AES.Instance.Encrypt(data.ToBytes()), EnvelopeType.AesDataBuffer);
        }
Example #12
0
        public FakeStruct Save(DataBuffer db)
        {
            FakeStruct fake = new FakeStruct(db, 29);

            fake[0] = db.AddData(this.GetType().Name, DataType.String);
            fake[1] = a;
            fake[2] = b;
            fake[3] = c;
            fake.SetInt64(4, d);
            fake.SetFloat(6, e);
            fake.SetDouble(7, f);
            fake.SetData(9, g);
            if (h != null)
            {
                fake[10] = db.AddData(h.Save(db));
            }
            v.Save(fake, 11);
            v3.Save(fake, 13);
            v4.Save(fake, 16);
            col.Save(fake, 20);
            col32.Save(fake, 24);
            q.Save(fake, 25);
            return(fake);
        }