예제 #1
0
        void HandleToken(NetworkMsg type, IMessageRider token)
        {
            byte[] data = token.ToByteArray();

            switch (type)
            {
            case NetworkMsg.Connect:
                ConnectToken = data;
                break;

            case NetworkMsg.Accept:
                AcceptToken = data;
                break;

            case NetworkMsg.Disconnect:
                DisconnectToken = data;
                break;

            case NetworkMsg.Refuse:
                RefuseToken = data;
                break;

            default:
                break;
            }
        }
예제 #2
0
        public byte[] WriteToken(IMessageRider token, NetworkMsg type)
        {
            byte[] tokenArray = token.ToByteArray();
            //Handle null tokens
            int tokenSize = 0;

            if (tokenArray != null)
            {
                tokenSize = tokenArray.Length;
            }
            //The size is a byte in bits (8) + the size of the token to transmit
            Packet p = new Packet(8 + tokenSize);

            p.WriteByte((byte)type);
            p.WriteToken(token);
            p.FinishWriting(); // Not necessary as our defination of this packet was precise, but still good form

            return(p.ByteBuffer);
        }
예제 #3
0
 void HandleAccepted(IMessageRider riderToken)
 {
     AcceptToken = riderToken.ToByteArray();
     accepted    = true;
 }