Esempio n. 1
0
        public void Loading()
        {
            //-----------------------------------------手动添加-----------------------------------------------------------
            CmdToCallManager <ZYSocketSuper, int, ReadBytes, SocketAsyncEventArgs> .GetInstance().AddCall(1000, LogOn);

            CmdToCallManager <ZYSocketSuper, int, ReadBytes, SocketAsyncEventArgs> .GetInstance().AddCall(800, Ping);

            CmdToCallManager <ZYSocketSuper, int, ReadBytes, SocketAsyncEventArgs> .GetInstance().AddCall(1002, ReadDataSet);

            //------------------------------------------标签自动添加CMD函数指针-------------------------------------------
            CmdToCallManager <ZYSocketSuper, ReadBytes, SocketAsyncEventArgs> .GetInstance().AddPackerObj(this);

            //-----------------------------------------注意2个类是不一样的------------------------------------------------
        }
Esempio n. 2
0
        static void DataOn(byte[] data, SocketAsyncEventArgs socketAsync)
        {
            ReadBytes read = new ReadBytes(data);

            int length;
            int cmd;

            if (read.ReadInt32(out length) && read.ReadInt32(out cmd) && length == read.Length)
            {
                if (!CmdToCallManager <ZYSocketSuper, ReadBytes, SocketAsyncEventArgs> .GetInstance().pointerRun(server, cmd, read, socketAsync)) //如果用户发送的是登入数据包
                {
                    server.Disconnect(socketAsync.AcceptSocket);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 数据包输入 以处理
        /// </summary>
        /// <param name="data"></param>
        /// <param name="session"></param>
        private void DataOn(byte[] data, ZYNetSession session)
        {
            ReadBytes read = new ReadBytes(data);

            int length;
            int cmd;

            if (read.ReadInt32(out length) && length == read.Length && read.ReadInt32(out cmd))
            {
                if (cmd != -2000)
                {
                    if (!CmdToCallManager <ZYNetServer, ReadBytes, ZYNetSession> .GetInstance().pointerRun(this, cmd, read, session))
                    {
                        LLOG("Not Find CMD:" + cmd, EventLogType.ERR);
                    }
                }
                else
                {
                    ProxyData tmp;

                    if (read.ReadObject <ProxyData>(out tmp))
                    {
                        if (tmp.Source == session.Id)
                        {
                            if (tmp.Ids != null)
                            {
                                if (tmp.Ids.Contains(0))
                                {
                                    if (UserDataInput != null)
                                    {
                                        UserDataInput(session, tmp.Data);
                                    }
                                }

                                foreach (var Id in tmp.Ids)
                                {
                                    if (Id != 0 && SessionDiy.ContainsKey(Id))
                                    {
                                        Service.SendData(SessionDiy[Id].Asyn.AcceptSocket, data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 数据包输入
        /// </summary>
        /// <param name="data">输入数据</param>
        /// <param name="socketAsync">该数据包的通讯SOCKET</param>
        static void BinaryInputHandler(byte[] data, SocketAsyncEventArgs socketAsync)
        {
            if (socketAsync.UserToken == null) //如果用户第一次登入
            {
                ReadBytes read = new ReadBytes(data);

                int length;
                int cmd;

                if (read.ReadInt32(out length) && length == read.Length && read.ReadInt32(out cmd))
                {
                    if (!CmdToCallManager <ZYSocketSuper, int, ReadBytes, SocketAsyncEventArgs> .GetInstance().pointerRun(server, cmd, read, socketAsync)) //如果用户发送的是登入数据包
                    {
                        server.Disconnect(socketAsync.AcceptSocket);
                    }
                }
                else //无法读取数据包 断开连接
                {
                    server.Disconnect(socketAsync.AcceptSocket);
                }
            }
            else
            {
                User.UserInfo user = socketAsync.UserToken as User.UserInfo; //读取用户USERTRKEN

                if (user != null)
                {
                    if (user.BuffManger.Write(data)) //这里的 4表示 数据包长度是用4字节的整数存储的 Int
                    {
                        byte[] pdata;

                        while (user.BuffManger.Read(out pdata))
                        {
                            DataOn(pdata, socketAsync);
                        }
                    }
                }
            }
        }
Esempio n. 5
0
 public void Loading()
 {
     CmdToCallManager <ZYNetServer, ReadBytes, ZYNetSession> .GetInstance().AddPackerObj(this);
 }