示例#1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void conn_OnMessage(object sender, Message e)
 {
     if (!ListenForPackets) return;
     if (OnPacket != null)
     {
         Packet packet = new Packet(e.Type);
         for (uint n = 0; n < e.Count; n++)
         {
             packet.Add(e[n]);
         }
         OnPacket(this, packet);
     }
     switch (e.Type)
     {
         case "init":
             WorldKey = Rot13(e.GetString(5));
             if (OnWorldKey != null) OnWorldKey(this, WorldKey);
             MapData = Init2Array(e);
             if (OnInit != null)
             {
                 User bot = new User(e.GetString(9), e.GetInt(6));
                 bot.Move.Position.X = (double)e.GetInt(7);
                 bot.Move.Position.Y = (double)e.GetInt(8);
                 Dictionary<int, int> potData = Init2Pot(e);
                 OnInit(this,
                     e.GetString(0),
                     e.GetString(1),
                     e.GetString(2),
                     e.GetInt(3),
                     e.GetInt(4),
                     WorldKey,
                     bot,
                     e.GetBoolean(10),
                     e.GetBoolean(11),
                     e.GetInt(12),
                     e.GetInt(13),
                     e.GetBoolean(14),
                     e.GetDouble(15),
                     e.GetBoolean(16),
                     MapData,
                     potData);
             }
             break;
         case "info":
             if (OnInfo != null) OnInfo(this, e.GetString(0), e.GetString(1));
             break;
         case "p":
             if (OnPotion != null) OnPotion(this, e.GetInt(0), e.GetInt(1), e.GetBoolean(2));
             break;
         case "write":
             if (OnWrite != null) OnWrite(this, e.GetString(0), e.GetString(1));
             break;
         case "upgrade":
             if (OnUpgrade != null) OnUpgrade(this);
             break;
         case "m":
             if (OnMove != null)
             {
                 User.Motion motion = new User.Motion();
                 motion.Position.X = e.GetDouble(1);
                 motion.Position.Y = e.GetDouble(2);
                 motion.Velocity.X = e.GetDouble(3);
                 motion.Velocity.Y = e.GetDouble(4);
                 motion.Acceleration.X = e.GetDouble(5);
                 motion.Acceleration.Y = e.GetDouble(6);
                 motion.KeyDown.X = e.GetDouble(7);
                 motion.KeyDown.Y = e.GetDouble(8);
                 OnMove(this, e.GetInt(0), motion, e.GetInt(9), e.GetBoolean(10), e.GetBoolean(11));
             }
             break;
         case "add":
             if (OnAdd != null || ListUsers)
             {
                 User u = new User(e.GetString(1), e.GetInt(0));
                 u.SmileyID = e.GetInt(2);
                 u.Move.Position.X = e.GetDouble(3);
                 u.Move.Position.Y = e.GetDouble(4);
                 u.isGod = e.GetBoolean(5);
                 u.isMod = e.GetBoolean(6);
                 u.isChat = e.GetBoolean(7);
                 u.Coins = e.GetInt(8);
                 u.isFriend = e.GetBoolean(9);
                 u.isPurple = e.GetBoolean(10);
                 u.Level = e.GetInt(11);
                 u.isClubMember = e.GetBoolean(12);
                 if (OnAdd != null) OnAdd(this, u);
                 if (ListUsers) Manager.UserJoined(u);
             }
             break;
         case "c":
             if (OnCoin != null) OnCoin(this, e.GetInt(0), e.GetInt(1));
             break;
         case "k":
             if (OnCrown != null) OnCrown(this, e.GetInt(0));
             break;
         case "ks":
             if (OnWin != null) OnWin(this, e.GetInt(0));
             break;
         case "b":
             if (OnBlock != null) OnBlock(this, e.GetInt(0), e.GetInt(1), e.GetInt(2), e.GetInt(3), e.GetInt(4), -1, -1, -1, -1, -1, "");
             break;
         case "bc":
             if (OnBlock != null) OnBlock(this, 0, e.GetInt(0), e.GetInt(1), e.GetInt(2), -1, e.GetInt(3), -1, -1, -1, -1, "");
             break;
         case "bs":
             if (OnBlock != null) OnBlock(this, 0, e.GetInt(0), e.GetInt(1), e.GetInt(2), -1, -1, e.GetInt(3), -1, -1, -1, "");
             break;
         case "pt":
             if (OnBlock != null) OnBlock(this, 0, e.GetInt(0), e.GetInt(1), e.GetInt(2), -1, -1, -1, e.GetInt(3), e.GetInt(4), e.GetInt(5), "");
             break;
         case "lb":
             if (OnBlock != null) OnBlock(this, 0, e.GetInt(0), e.GetInt(1), e.GetInt(2), -1, -1, -1, -1, -1, -1, e.GetString(3));
             break;
         case "br":
             if (OnBlock != null) OnBlock(this, 0, e.GetInt(0), e.GetInt(1), e.GetInt(2), -1, -1, -1, e.GetInt(3), -1, -1, "");
             break;
         case "show":
             if (OnShow != null) OnShow(this, e.GetString(0));
             break;
         case "hide":
             if (OnHide != null) OnHide(this, e.GetString(0));
             break;
         case "face":
             if (OnFace != null) OnFace(this, e.GetInt(0), e.GetInt(1));
             break;
         case "god":
             if (OnGod != null) OnGod(this, e.GetInt(0), e.GetBoolean(1));
             break;
         case "mod":
             if (OnMod != null) OnMod(this, e.GetInt(0));
             break;
         case "lostaccess":
             if (OnLostAccess != null) OnLostAccess(this);
             break;
         case "access":
             if (OnAccess != null) OnAccess(this);
             break;
         case "allowpotions":
             if (OnAllowPotions != null)
             {
                 List<int> potions = new List<int>();
                 for (uint n = 1; n < e.Count; n++)
                 {
                     potions.Add(e.GetInt(n));
                 }
                 OnAllowPotions(this, e.GetBoolean(0), potions.ToArray());
             }
             break;
         case "wu":
             if (OnWootUp != null) OnWootUp(this, e.GetInt(0));
             break;
         case "w":
             if (OnWoot != null) OnWoot(this, e.GetInt(0));
             break;
         case "levelup":
             if (OnLevelUp != null) OnLevelUp(this, e.GetInt(0), e.GetInt(1));
             break;
         case "say":
             if (OnSay != null) OnSay(this, e.GetInt(0), e.GetString(1));
             break;
         case "say_old":
             if (OnSayOld != null) OnSayOld(this, e.GetString(0), e.GetString(1));
             break;
         case "updatemeta":
             if (OnUpdateMeta != null) OnUpdateMeta(this, e.GetString(0), e.GetString(1), e.GetInt(2), e.GetInt(3), e.GetInt(4));
             break;
         case "autotext":
             if (OnQuickChat != null) OnQuickChat(this, e.GetInt(0), e.GetString(1));
             break;
         case "left":
             if (OnLeft != null) OnLeft(this, e.GetInt(0));
             if (ListUsers) Manager.UserLeft(e.GetInt(0));
             break;
         case "clear":
             if (OnClear != null) OnClear(this, e.GetInt(0), e.GetInt(1));
             break;
         case "tele":    //owner reset level OR a user got killed
             if (OnReset != null)
             {
                 List<SpawnInfo> si = new List<SpawnInfo>();
                 for (uint n = 1; n < e.Count; n += 3)
                 {
                     si.Add(new SpawnInfo(e.GetInt(n), e.GetInt(n + 1), e.GetInt(n + 2)));
                 }
                 OnReset(this, e.GetBoolean(0), si.ToArray());
             }
             break;
         case "reset":   // owner loded level
             MapData = Load2Array(e);
             if (OnLoadLevel != null) OnLoadLevel(this, MapData);
             break;
         case "saved":
             if (OnSave != null) OnSave(this);
             break;
         default:
             if (OnOther != null)
             {
                 Packet packet = new Packet(e.Type);
                 for (uint n = 0; n < e.Count; n++)
                 {
                     packet.Add(e[n]);
                 }
                 OnOther(this, packet);
             }
             break;
     }
 }
示例#2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="p"></param>
 public void Send(Packet p)
 {
     Send(p.Type, p.Parameters);
 }