Exemple #1
0
    private void OnConnect(Sproto.SprotoTypeBase _)
    {
        Debug.Log("on connect");
        ClientNet.inst.Send <Protocol.handshake>(null, evt =>
        {
            SprotoType.handshake.response response = evt as SprotoType.handshake.response;
            Debug.Log("on msg " + response.msg);
        });

        SprotoType.register_account.request req = new SprotoType.register_account.request();
        req.account  = "test account";
        req.password = "******";
        ClientNet.inst.Send <Protocol.register_account>(req, evt =>
        {
            SprotoType.register_account.response response = evt as SprotoType.register_account.response;
            Debug.Log("on msg " + response.msg);
        });

        //SprotoType.login_account.request loginReq = new SprotoType.login_account.request();
        //loginReq.account = "test account";
        //loginReq.password = "******";
        //ClientNet.inst.Send<Protocol.login_account>(loginReq, e =>
        //{
        //    SprotoType.login_account.response res = e as SprotoType.login_account.response;
        //    Debug.Log("on login " + res.result);
        //});
    }
Exemple #2
0
            public static void __Dispatch(SprotoRpc.RpcInfo info)
            {
                Sproto.SprotoTypeBase ret = null;
                switch (info.tag)
                {
                case Protocol.foobar.Tag:
                    ret = S2C.foobar((SprotoType.foobar.request)info.requestObj);
                    break;

                case Protocol.foo.Tag:
                    ret = S2C.foo();
                    break;

                case Protocol.blackhole.Tag:
                    S2C.blackhole((SprotoType.blackhole.request)info.requestObj);
                    break;

                case Protocol.bar.Tag:
                    S2C.bar();
                    break;

                default:
                    break;
                }
                if (null != info.Response)
                {
                    SendData(info.Response(ret));
                }
            }
Exemple #3
0
            public byte[] Invoke <T>(SprotoTypeBase request = null, long?session = null)
            {
                int tag = protocol[typeof(T)];

                ProtocolFunctionDictionary.MetaInfo info = protocol[tag];
#if (!INCLUDE_IL2CPP)
                if (request != null && request.GetType() != info.Request.Key)
                {
                    throw new Exception("request type: " + request.GetType().ToString() + "not is expected. [" + info.Request.Key.GetType().ToString() + "]");
                }
#endif
                package.clear();
                package.type = tag;

                if (session != null)
                {
                    rpc.sessionDictionary.Add((long)session, info.Response.Value);
                    package.session = (long)session;
                }

                stream.Seek(0, System.IO.SeekOrigin.Begin);
                int len = package.encode(stream);

                if (request != null)
                {
                    len += request.encode(stream);
                }

                return(spack.pack(stream.Buffer, len));
            }
Exemple #4
0
            public byte[] Request(SprotoProtocolBase protocol, int session)
            {
                PackageType.Package package = new PackageType.Package();
                int tag = protocol.GetTag();

                package.type    = tag;
                package.session = session;
                ProtocolFunctionDictionary.ProtocolInfo info = ProtocolFunctionDictionary.GetProtocolInfo(tag);

                if (info.Response != null)
                {
                    this.sessionDictionary.Add(session, tag);
                }

                this.stream.Seek(0, System.IO.SeekOrigin.Begin);
                int            len     = package.encode(this.stream);
                SprotoTypeBase request = protocol.GetRequest();

                if (request != null)
                {
                    len += request.encode(this.stream);
                }

                return(this.spack.pack(this.stream.Buffer, len));
            }
        private int encode_struct(SprotoTypeBase obj)
        {
            byte[] data = obj.encode();

            this.fill_size(data.Length);
            this.data.Write(data, 0, data.Length);

            return(SprotoTypeSize.sizeof_length + data.Length);
        }
Exemple #6
0
 private SprotoTypeBase _gen(KeyValuePair <Type, typeFunc> field, int tag, byte[] buffer, int offset = 0)
 {
     if (field.Value != null)
     {
         SprotoTypeBase obj = field.Value(buffer, offset);
         if (obj.GetType() != field.Key)
         {
             throw new Exception("sproto type: " + obj.GetType().ToString() + "not is expected. [" + field.Key.ToString() + "]");
         }
         return(obj);
     }
     return(null);
 }
        private int encode_struct(SprotoTypeBase obj)
        {
            int sz_pos = this.data.Position;

            this.data.Seek(SprotoTypeSize.sizeof_length, SeekOrigin.Current);
            int len     = obj.encode(this.data);
            int cur_pos = this.data.Position;

            this.data.Seek(sz_pos, SeekOrigin.Begin);
            this.fill_size(len);
            this.data.Seek(cur_pos, SeekOrigin.Begin);

            return(SprotoTypeSize.sizeof_length + len);
        }
Exemple #8
0
        static private SprotoTypeBase _gen(Dictionary <int, KeyValuePair <Type, typeFunc> > dictionary, int tag, byte[] buffer, int offset = 0)
        {
            KeyValuePair <Type, typeFunc> v;

            if (dictionary.TryGetValue(tag, out v))
            {
                SprotoTypeBase obj = v.Value(buffer, offset);
                if (obj.GetType() != v.Key)
                {
                    SprotoTypeSize.error("sproto type: " + obj.GetType().ToString() + "not is expected. [" + v.Key.ToString() + "]");
                }
                return(obj);
            }

            return(null);
        }
    private void OnConnect(Sproto.SprotoTypeBase _)
    {
        Debug.Log("on connect");
        ClientNet.inst.Send <Protocol.handshake>(null, evt =>
        {
            SprotoType.handshake.response response = evt as SprotoType.handshake.response;
            Debug.Log("on msg " + response.msg);
        });

        SprotoType.register_account.request req = new SprotoType.register_account.request();
        req.account  = "test account";
        req.password = "******";
        ClientNet.inst.Send <Protocol.register_account>(req, evt =>
        {
            SprotoType.register_account.response response = evt as SprotoType.register_account.response;
            Debug.Log("on msg " + response.msg);
        });
    }
 public void write_obj(SprotoTypeBase obj, int tag)
 {
     this.encode_struct(obj);
     this.write_tag(tag, 0);
 }
Exemple #11
0
 private void OnConnect(Sproto.SprotoTypeBase _)
 {
     Debug.Log("on connect");
 }