コード例 #1
0
        static void handleRequestEnter(InputPacket ip, User u)
        {
            Console.WriteLine("handlerE");
            OutputPacket op1 = new OutputPacket(512, Protocol.RESPONSE_ENTER);

            u.setUserName(ip.readBytes());
            op1.writeUser(u);

            op1.writeInt32(usrList.Count);

            foreach (User otherUsr in usrList)
            {
                op1.writeUser(otherUsr);
            }
            u.sendPacketAsync(op1);

            OutputPacket op2 = new OutputPacket(512, Protocol.BROADCAST_ENTER);

            op2.writeUser(u);
            foreach (User otherUsr in usrList)
            {
                otherUsr.sendPacketAsync(op2);
            }

            usrList.Add(u);
            //Console.WriteLine("HEOS");
        }
コード例 #2
0
ファイル: User.cs プロジェクト: HyunSeoChoi/tcp-packing
 public void sendPacketAsync(OutputPacket op)
 {
     if (op.getLength() > Global.MAX_OUTPUT_PACKET_LEN)
     {
         Console.WriteLine("sendPacket length is greater than MAX_PACKET_LEN");
         return;
     }
     try
     {
         usrSocket.BeginSend(op.wrapPacket(), 0, op.getLength(), SocketFlags.None, sendPacketComplete, null);
     }
     catch (Exception e)
     {
         close();
     }
 }
コード例 #3
0
        static void handleRequestChangeDestination(InputPacket ip, User u)
        {
            OutputPacket op  = new OutputPacket(512, Protocol.BROADCAST_CHANGE_DESTINATION);
            int          key = u.getKey();

            op.writeInt32(key);
            op.writeVector2(u.posVec);
            Vector2 newDestinaton = ip.readVector2();

            op.writeVector2(newDestinaton);
            u.destinationVec = newDestinaton;

            //Console.WriteLine(key + u.posVec.x + ", " + u.posVec.y + " " + newDestinaton.x + "," + newDestinaton.y);
            foreach (User otherUsr in usrList)
            {
                otherUsr.sendPacketAsync(op);
            }
        }