Exemple #1
0
        private void Handshake(Stream palstream, MH_Logon handshake = null)
        {
            //We do this 'dirty' because of the extra handling for the yet-unknown endianness

            {
                var buf = new byte[4];
                palstream.Read(buf, 0, 4);

                EndianBitConverter endianness;

                int eventType = BitConverter.ToInt32(buf, 0);
                switch ((MessageTypes)eventType)
                {
                    case MessageTypes.DIYIT:
                        endianness = EndianBitConverter.Big;
                        Debug.WriteLine("BigEndian server handshake");
                        break;
                    case MessageTypes.TIYID:
                        endianness = EndianBitConverter.Little;
                        Debug.WriteLine("LittleEndian server handshake");
                        break;
                    default:
            #if DEBUG
                        var totes = new byte[12];
                        Array.Copy(buf, totes, 4);

                        palstream.Read(buf, 0, 4);
                        Array.Copy(buf, 0, totes, 4, 4);

                        palstream.Read(buf, 0, 4);
                        Array.Copy(buf, 0, totes, 8, 4);

                        var cmsg = totes.MarshalStruct<ClientMessage>();

                        Console.WriteLine(cmsg);
            #endif
                        throw new Exception(string.Format("unrecognized handshake event: 0x{0:X8}", eventType));
                }

                Reader = new EndianBinaryReader(endianness, palstream);
                Writer = new EndianBinaryWriter(endianness, palstream);
            }

            uint length = Reader.ReadUInt32();
            int refNum = Reader.ReadInt32(); //userID for client

            Palace.CurrentUser = Palace.GetUserByID(refNum, true);

            short desiredRoom = 0;
            short.TryParse(targetUri.AbsolutePath.TrimStart('/'), out desiredRoom);

            reset = handshake ?? new MH_Logon(this, Identity.Name, desiredRoom);
            reset.Write();
        }
Exemple #2
0
 private void HandleMessage(ClientMessage msg)
 {
     switch (msg.eventType)
     {
         case MessageTypes.ALTLOGONREPLY:
             var altreset = new MH_Logon(this);
             var altrec = altreset.Record;
     #if OFFLINE
             break;
     #endif
             var rec = reset.Record;
             Debug.WriteLine("AltLogonReply.");
             if (altrec.puidCRC != rec.puidCRC && altrec.puidCtr != rec.puidCtr)
             {
                 Debug.WriteLine("Server changed our puid data. Reconnecting.");
                 Signoff();
             }
             break;
         case MessageTypes.PING:
             Debug.WriteLine("Ping.");
             var msg_pingpong = new MH_PingPong(this, msg);
             msg_pingpong.Write();
             Debug.WriteLine("Pong.");
             break;
         case MessageTypes.USERSTATUS:
             var msg_ustatus = new MH_UserStatus(this, msg);
             break;
         case MessageTypes.USERMOVE:
             var msg_umove = new MH_UserMove(this, msg);
             break;
         case MessageTypes.USERPROP:
             var msg_uprop = new MH_UserProp(this, msg);
             break;
         case MessageTypes.USERLOG:
             var msg_ulog = new MH_UserLog(this, msg);
             break;
         case MessageTypes.USERLIST:
             var msg_ulist = new MH_UserList(this, msg);
             break;
         case MessageTypes.USEREXIT:
             var msg_uexit = new MH_UserExit(this, msg);
             break;
         case MessageTypes.USERNEW:
             var msg_unew = new MH_UserNew(this, msg);
             break;
         case MessageTypes.LOGOFF:
             var msg_logoff = new MH_Logoff(this, msg);
             break;
         case MessageTypes.TALK:
             var msg_talk = new MH_Talk(this);
             Debug.WriteLine("(fromuser {1}) msg: `{0}`", msg_talk.Text, msg.refNum);
             break;
         case MessageTypes.XTALK:
             var msg_xtalk = new MH_XTalk(this, msg);
             Debug.WriteLine("(fromuser {1}) msg: `{0}`", msg_xtalk.Text, msg.refNum);
     #if CLEVER
             if (Identity.ID != msg.refNum)
             {
                 var newxtalk = new MH_XTalk(this, clever.Think(msg_xtalk.Text));
                 newxtalk.Write();
             }
     #endif
             break;
         case MessageTypes.WHISPER:
             var msg_whisp = new MH_Whisper(this, msg);
             Debug.WriteLine("(fromuser {1}) msg: `{0}`", msg_whisp.Text, msg_whisp.Target.ID);
             //if (msg_whisp.Target.ID != Identity.ID)
             //{
             //    var msg_whisp_out = new MH_Whisper(this, msg_whisp.Target, new string(msg_whisp.Text.Reverse().ToArray()));
             //    msg_whisp_out.Write();
             //}
             break;
         case MessageTypes.XWHISPER:
             var msg_xwhisp = new MH_XWhisper(this, msg);
             Debug.WriteLine("(fromuser {1}) msg: `{0}`", msg_xwhisp.Text, msg_xwhisp.Target.ID);
     #if CLEVER
             if (msg_xwhisp.Target.ID != Identity.ID)
             {
                 //var msg_xwhisp_out = new MH_XWhisper(this, msg_xwhisp.Target, clever.Think(msg_xwhisp.Text));
                 var msg_xwhisp_out = new MH_XWhisper(this, msg_xwhisp.Target, new string(msg_xwhisp.Text.Reverse().ToArray()));
                 msg_xwhisp_out.Write();
             }
     #endif
             break;
         case MessageTypes.ROOMDESC:
             var msg_roomdesc = new MH_RoomDesc(this, msg);
             break;
         case MessageTypes.ROOMDESCEND:
             break;
         case MessageTypes.ASSETSEND:
             var msg_assetsend = new MH_AssetSend(this, msg);
             break;
         case MessageTypes.VERSION:
             var mh_sv = new MH_ServerVersion(this, msg);
             break;
         case MessageTypes.SERVERINFO:
             var msg_svinfo = new MH_ServerInfo(this, msg);
             break;
         case MessageTypes.HTTPSERVER:
             var msg_httpsv = new MH_HTTPServer(this);
             break;
         case MessageTypes.BLOWTHRU:
             var msg_blowthru = new MH_Blowthru(this, msg);
     #if OFFLINE
             blowthrus.Add(msg_blowthru.Payload);
     #endif
             break;
         default:
             //for (int i = 0; i < 500; i++)
             //    new MH_XWhisper(this, Palace.GetUserByID(msg.refNum), "hi").Write();
             Debug.WriteLine("Unknown EvT: {0} (0x{1:X8})", msg.eventType, (uint)msg.eventType);
             Reader.ReadBytes(msg.length);
             break;
     }
 }