Exemplo n.º 1
0
    //创建空数据包
    public static WritePacket CreateNullPacket()
    {
        WritePacket wp = new WritePacket();

        wp.WriteInt8(MsgOutsideDef.MsgNull);
        return(wp);
    }
Exemplo n.º 2
0
        public void WriteToSslStream(WritePacket packet)
        {
            _curwritePacket = packet;
            ArraySegment <byte> tmparr = packet.Stream.GetIOBuffer();

            this._sslstream.Write(tmparr.Array, tmparr.Offset, packet.Stream.Length);
        }
Exemplo n.º 3
0
    public CmdInputAction(short t, long aid, byte action, byte not, long to = 0)
    {
        cmdType = t;
        switch (not)
        {
        case MsgBroadcastType.Peer:
            wp = PacketFunc.CreatePeerPacket(to);
            break;

        case MsgBroadcastType.Broadcast:
            wp = PacketFunc.CreateBroadcastPacket(true);
            break;

        case MsgBroadcastType.BroadcastNot:
            wp = PacketFunc.CreateBroadcastPacket(false);
            break;

        default:
            wp = PacketFunc.CreateBroadcastPacket(true);
            break;
        }
        wp.WriteInt16(MsgInsideDef.MsgInputAction);
        wp.WriteInt8(action);
        wp.WriteInt64(aid);
    }
Exemplo n.º 4
0
 public CmdChatText(short t, string msg, bool not)
 {
     cmdType = t;
     wp      = PacketFunc.CreateBroadcastPacket(not); //广播是否包括自己
     wp.WriteInt16(MsgInsideDef.MsgChatText);
     wp.WriteString(msg);
 }
Exemplo n.º 5
0
        private async Task HandleTCPReceive_RT(SocketReceiveEventArgs args)
        {
            switch (args.ReadPacket.OpCode)
            {
            case 0:
                string guid     = args.ReadPacket.ReadString();
                string roomId   = args.ReadPacket.ReadString();
                string clientId = args.ReadPacket.ReadString();
                if (tempUsersDick.TryGetValue(guid, out NetSocket netSocket))
                {
                    tempUsersDick.Remove(guid);
                    await AddClient(roomId, clientId, new NetSocket(netSocket.MainSocket, NetManager.BUFFER_LENGTH));

                    WritePacket wr = new WritePacket(NetManager.RT_PACKET_OPCODE1);
                    netSocket.Send(wr);
                }
                else
                {
                }
                break;

            default:
                break;
            }
            await Task.FromResult(true);
        }
Exemplo n.º 6
0
    //fire2按钮
    public void OnFire2Btn()
    {
        var         cmd = new CmdInputAction(MsgInsideDef.MsgInputAction, agent.GetConnectID(), InputType.Fire2, MsgBroadcastType.Broadcast);
        WritePacket wp  = cmd.Packet();

        wp.WriteFloat32(5.8f);
        cmd.Send(agent);
    }
Exemplo n.º 7
0
    //创建单发数据包
    public static WritePacket CreatePeerPacket(Int64 to)
    {
        WritePacket wp = new WritePacket();

        wp.WriteInt8(MsgOutsideDef.MsgPeer);
        wp.WriteInt64(to);
        return(wp);
    }
Exemplo n.º 8
0
 IEnumerator ping()
 {
     while (keepPing && true)
     {
         WritePacket wp = PacketFunc.CreateNullPacket();
         client.Send(wp.ToArray());
         yield return(new WaitForSeconds(8));
     }
 }
Exemplo n.º 9
0
    //创建群发数据包
    public static WritePacket CreateBroadcastPacket(bool notself)
    {
        WritePacket wp = new WritePacket();

        wp.WriteInt8(MsgOutsideDef.MsgBroadcast);
        wp.WriteInt64(0);
        wp.WriteInt8(notself ? (byte)1 : (byte)0);
        return(wp);
    }
Exemplo n.º 10
0
        /// <summary>
        /// 触发写入包的发送失败事件
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        public void ChannelWriteErr(IContext context, object msg)
        {
            WritePacket packet = msg as WritePacket;

            if (packet != null)
            {
                packet.EmitErr(context);
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// 触发写入包的发送成功事件
        /// </summary>
        /// <param name="context"></param>
        /// <param name="msg"></param>
        public void ChannelWriteFinish(IContext context, object msg)
        {
            WritePacket packet = msg as WritePacket;

            if (packet != null)
            {
                packet.EmitSuccess(context);
            }
        }
Exemplo n.º 12
0
        private async Task HandleTCPRT(NetSocket netSocket)
        {
            Guid guid = Guid.NewGuid();

            tempUsersDick.Add(guid.ToString(), netSocket);
            // TODO Complete TCP Connection
            WritePacket wr = new WritePacket(NetManager.RT_PACKET_OPCODE0);

            wr.AddString(guid.ToString());
            netSocket.Send(wr);
            await Task.FromResult(true);
        }
Exemplo n.º 13
0
        public async Task <bool> Send(string id, WritePacket wr)
        {
            NetSocket client = await FindSocket(id);

            if (client != null)
            {
                client.Send(wr);
                return(await Task.FromResult(true));
            }
            else
            {
                return(await Task.FromResult(false));
            }
        }
Exemplo n.º 14
0
 public async Task <bool> Send(WritePacket wr)
 {
     if (netSockets.Count > 0)
     {
         foreach (var item in netSockets)
         {
             item.Value.Send(wr);
         }
         return(await Task.FromResult(true));
     }
     else
     {
         return(await Task.FromResult(false));
     }
 }
Exemplo n.º 15
0
    public void OnStartGame()
    {
        if (!isStart && agent.GetIds().Count >= MinPlayerCount)
        {
            var         cmd = new CmdInputAction(MsgInsideDef.MsgInputAction, agent.GetConnectID(), InputType.ButtonA, MsgBroadcastType.BroadcastNot);
            WritePacket wp  = cmd.Packet();
            cmd.Send(agent);

            Debug.Log("Click startGame");
        }
        else
        {
            Debug.Log("Player Count: " + agent.GetIds().Count);
        }
    }
Exemplo n.º 16
0
 public override void ChannelWrite(IContext context, object msg)
 {
     if (EnsureAuthenticated())
     {
         if (!(msg is SSLWritePacket))
         {
             //判断是否非SSL包,是则进行SSL封包,并将当前包当作
             WritePacket wp = msg as WritePacket;
             if (wp != null)
             {
                 _agent.WriteToSslStream(wp);
                 return;
             }
         }
     }
     context.FirePreWrite(msg);
 }
Exemplo n.º 17
0
    // Update is called once per frame
    void Update()
    {
        if (isStart && Input.GetMouseButtonDown(0))
        {
            Debug.Log("鼠标左键点击");
            var         cmd = new CmdInputAction(MsgInsideDef.MsgInputAction, agent.GetConnectID(), InputType.ButtonC, MsgBroadcastType.Broadcast);
            WritePacket wp  = cmd.Packet();
            wp.WriteInt32(isMain?1:0);
            cmd.Send(agent);
        }

        if (Input.GetMouseButtonDown(1))
        {
            blue.GetComponent <Rigidbody>().AddForce(0, 500, 0);
            Debug.Log("右键点击");
        }
    }
Exemplo n.º 18
0
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     _curwritePacket = null;
     Write(buffer, offset, count);
     if ((_state & SSLHandlerState.Authenticating) != 0 && _needRead)
     {
         //如果是在握手阶段则使用异步,需要读取才结束
         _AsyncWrite            = new SSLAsyncResult <int>();
         _AsyncWrite.Callback   = callback;
         _AsyncWrite.AsyncState = state;
         return(_AsyncWrite);
     }
     else
     {
         SSLSyncResult <int> result = new SSLSyncResult <int>();
         result.AsyncState = state;
         return(result);
     }
 }
Exemplo n.º 19
0
    /// <summary>
    /// 动作回调
    /// </summary>

    public void OnAction(long id, byte action, ReadPacket rp)
    {
        switch (action)
        {
        case InputType.ButtonA:
            var         cmd = new CmdInputAction(MsgInsideDef.MsgInputAction, agent.GetConnectID(), InputType.ButtonD, MsgBroadcastType.Peer, id);
            WritePacket wp  = cmd.Packet();
            cmd.Send(agent);
            isStart = true;
            startGame.gameObject.SetActive(false);
            break;

        case InputType.ButtonC:
            Debug.Log("ButtonC");
            int isM = rp.ReadInt32();
            if (isM == 1)
            {
                blue.GetComponent <Rigidbody>().AddForce(0, 500, 0);
            }
            else
            {
                red.GetComponent <Rigidbody>().AddForce(0, 500, 0);
            }
            break;

        case InputType.ButtonD:
            isStart = true;
            isMain  = true;
            startGame.gameObject.SetActive(false);
            break;

        case InputType.Fire2:
            Debug.Log("收到动作命令, ID: " + id + " 动作: " + action + " 附加数据: " + rp.ReadFloat32());
            break;

        default:
            Debug.Log("收到动作命令, ID: " + id + " 动作: " + action);
            break;
        }
    }
Exemplo n.º 20
0
        private static void HandleTCPReceive(SocketReceiveEventArgs args)
        {
            switch (args.ReadPacket.OpCode)
            {
            case 0:
                string guid = args.ReadPacket.ReadString();
                Console.WriteLine("Received : {0}", guid);
                WritePacket wr = new WritePacket(0);
                wr.AddString(guid);
                wr.AddString(matchId);
                wr.AddString(Id);
                tcpSocket.Send(wr);
                break;

            case 1:
                Console.WriteLine("You Can Play Now");
                break;

            default:
                break;
            }
        }
Exemplo n.º 21
0
 public SSLWritePacket(WritePacket parent)
 {
     _parent = parent;
 }
Exemplo n.º 22
0
 private void OnWritePacket(int size)
 {
     WritePacket?.Invoke(this, size);
 }
Exemplo n.º 23
0
 void Start()
 {
     devinfo["motor"]   = new WritePacket(0x09, 0xaa, "motor", "short");
     devinfo["led"]     = new WritePacket(0x03, 0xab, "led", "byte");
     devinfo["marquee"] = new WritePacket(0x05, 0xac, "marquee", "byte");
 }