protected virtual void OnMessage(object sender, PlayerIOClient.Message m) { switch (m.Type) { case "add": { int ID = m.GetInt(0); if (!playerList.ContainsKey(ID)) { Player temp = new Player((Bot)this, ID, m.GetString(1), m.GetInt(2), m.GetFloat(3), m.GetFloat(4), m.GetBoolean(5), m.GetBoolean(6), m.GetBoolean(7), m.GetInt(8), m.GetBoolean(10), m.GetBoolean(9), m.GetInt(11)); temp.x = m.GetDouble(3); temp.y = m.GetDouble(4); lock (playerList) { playerList.Add(ID, temp); } if (nameList.ContainsKey(temp.name)) nameList.Remove(temp.name); nameList.Add(temp.name, ID); } } break; case "left": { int tempKey = m.GetInt(0); if (playerList.ContainsKey(tempKey)) { nameList.Remove(playerList[tempKey].name); lock (playerList) { playerList.Remove(tempKey); } } } break; case "m": { int playerID = int.Parse(m[0].ToString()); float playerXPos = float.Parse(m[1].ToString()); float playerYPos = float.Parse(m[2].ToString()); float playerXSpeed = float.Parse(m[3].ToString()); float playerYSpeed = float.Parse(m[4].ToString()); float modifierX = float.Parse(m[5].ToString()); float modifierY = float.Parse(m[6].ToString()); int xDir = int.Parse(m[7].ToString()); int yDir = int.Parse(m[8].ToString()); if (playerList.ContainsKey(playerID)) { lock (playerList) { Player player = playerList[playerID]; player.x = playerXPos; player.y = playerYPos; player.speedX = playerXSpeed; player.speedY = playerYSpeed; player.modifierX = modifierX; player.modifierY = modifierY; player.horizontal = xDir; player.vertical = yDir; playerList[playerID] = player; } } } break; case "god": { int tempKey = m.GetInt(0); if (playerList.ContainsKey(tempKey)) { Player player = playerList[tempKey]; player.isgod = m.GetBoolean(1); lock (playerList) { playerList[tempKey] = player; } } } break; case "face": { int tempKey = m.GetInt(0); if (playerList.ContainsKey(tempKey)) { Player player = playerList[tempKey]; player.frame(m.GetInt(1)); lock (playerList) { playerList[tempKey] = player; } } } break; case "k": //player got crown { int userId = m.GetInt(0); if (playerList.ContainsKey(userId)) { lock (playerList) { foreach (Player p in playerList.Values) { p.hascrown = false; } playerList[userId].hascrown = true; } } } break; case "ks": //player got silver crown { int userId = m.GetInt(0); if (playerList.ContainsKey(userId)) { lock (playerList) playerList[userId].hascrownsilver = true; } } break; case "c": //player took coin { int userId = m.GetInt(0); int totalCoins = m.GetInt(1); if (playerList.ContainsKey(userId)) { lock (playerList) playerList[userId].coins = totalCoins; } } break; case "levelup": { int userId = m.GetInt(0); int level = m.GetInt(1); if (playerList.ContainsKey(userId)) { lock (playerList) playerList[userId].level = level; } } break; case "tele": //owner used reset/load { bool resetUsed = m.GetBoolean(0); for (int i = 1; i < m.Count; i += 3) { int userId = m.GetInt(1); int spawnPosX = m.GetInt(2); int spawnPosY = m.GetInt(3); if (playerList.ContainsKey(userId)) { lock (playerList) { Player p = playerList[userId]; p.setPosition(spawnPosX * 16, spawnPosY * 16); playerList[userId] = p; } } } } break; } }
public override void onMessage(PlayerIOClient.Message m) { //MessageBox.Show(m.ToString()); switch (m.Type) { case "init": { DeserializeInit(m); bot.Connection.Send("init2"); bot.Connection.Send("init2"); break; } case "reset": { LoadWorld(m, 0, width, height); break; } case "add": { int id = m.GetInt(0); if (!players.ContainsKey(id)) { Player player = new Player(bot, id, m.GetString(1), m.GetInt(2), m.GetDouble(3), m.GetDouble(4), m.GetBoolean(5), m.GetBoolean(6), m.GetBoolean(7), m.GetInt(8), m.GetBoolean(10), m.GetBoolean(11), m.GetInt(9)); //player.IsClubMember = m.GetBoolean(14); players.Add(id, player); if (!namePlayers.ContainsKey(player.Name)) namePlayers.Add(new KeyValuePair<string, List<IPlayer>>(player.Name, new List<IPlayer>())); namePlayers[player.Name].Add(player); if (disconnectedPlayers.ContainsKey(player.Name)) disconnectedPlayers.Remove(player.Name); } break; } case "left": { int id = m.GetInt(0); if (players.ContainsKey(id)) { IPlayer left = players[id]; if (left != null) { if (!disconnectedPlayers.ContainsKey(left.Name)) disconnectedPlayers.Add(new KeyValuePair<string, List<IPlayer>>(left.Name, new List<IPlayer>())); disconnectedPlayers[left.Name].Add(left); } namePlayers.Remove(players[id].Name); players.Remove(id); } break; } case "m": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].X = m.GetDouble(1); players[id].Y = m.GetDouble(2); players[id].SpeedX = m.GetDouble(3); players[id].SpeedY = m.GetDouble(4); players[id].ModifierX = m.GetInt(5); players[id].ModifierY = m.GetInt(6); players[id].Horizontal = m.GetInt(7); players[id].Vertical = m.GetInt(8); players[id].Coins = m.GetInt(9); players[id].Purple = m.GetBoolean(10); //players[id].Levitation = m.GetBoolean(11); } break; } case "c": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Coins = m.GetInt(1); } break; } case "k": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].HasCrown = true; } break; } case "ks": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].HasCrownSilver = true; } break; } case "face": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Smiley = m.GetInt(1); } break; } case "god": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Respawn(); players[id].IsGod = m.GetBoolean(1); } break; } case "mod": { int id = m.GetInt(0); if (players.ContainsKey(id)) players[id].IsMod = m.GetBoolean(1); break; } case "lostaccess": { hasAccess = false; break; } case "access": { hasAccess = true; break; } case "info": break; case "p": break; case "upgrade": break; case "b": case "bc": case "bs": case "pt": case "lb": case "br": case "wp": case "ts": HandleBlockPlace(m); break; case "show": { string type = m.GetString(0); switch (type) { case "red": this.hideRed = false; break; case "green": this.hideGreen = false; break; case "blue": this.hideBlue = false; break; case "timedoor": this.hideTimeDoor = false; break; } } break; case "hide": { string type = m.GetString(0); switch (type) { case "red": this.hideRed = true; break; case "green": this.hideGreen = true; break; case "blue": this.hideBlue = true; break; case "timedoor": this.hideTimeDoor = true; break; } } break; case "allowpotions": break; case "wu": { int id = m.GetInt(0); if (isOwner && players.ContainsKey(id)) { players[id].Reply("Thank you!"); } } break; case "w": break; case "levelup": { int id = m.GetInt(0); if (players.ContainsKey(id)) { players[id].Level = m.GetInt(1); } } break; case "write": { if (m.GetString(0).Contains(" > you")) { string[] split = m.GetString(0).Split(' '); if (split.Length > 1) { string senderName = split[1]; if (namePlayers.ContainsKey(senderName)) { IPlayer sender = namePlayers[senderName].First(); string text = m.GetString(1); if (text.Length > 0 && text[0].Equals('!')) { string textCommandCharRemoved = text.Remove(0, 1); string[] textSplit = textCommandCharRemoved.Split(' '); string cmd = textSplit[0]; string[] args = new string[textSplit.Length - 1]; if (textSplit.Length > 0) Array.Copy(textSplit, 1, args, 0, textSplit.Length - 1); bot.SubBotHandler.onCommand(cmd, args, sender); } } } } } break; case "say": { int id = m.GetInt(0); string text = m.GetString(1); if (players.ContainsKey(id)) { IPlayer player = players[id]; if (text.Length > 0 && text[0].Equals('!')) { string textCommandCharRemoved = text.Remove(0, 1); string[] textSplit = textCommandCharRemoved.Split(' '); string cmd = textSplit[0]; string[] args = new string[textSplit.Length - 1]; if (textSplit.Length > 0) Array.Copy(textSplit, 1, args, 0, textSplit.Length - 1); bot.SubBotHandler.onCommand(cmd, args, player); } } } break; case "say_old": break; case "updatemeta": { owner = m.GetString(0); title = m.GetString(1); plays = m.GetInt(2); woots = m.GetInt(3); totalWoots = m.GetInt(4); } break; case "autotext": break; case "clear": { blockMap.Clear(); if (minimap != null) { minimap.Die(); minimap = new Minimap.Minimap(bot, width, height); foreach (Player player in players.Values) minimap.DrawPlayer(player); } else minimap = new Minimap.Minimap(bot, width, height); DrawBorder(); } break; case "tele": { bool usedReset = m.GetBoolean(0); for (int i = 1; i <= m.Count - 1; i += 3) { int playerId = m.GetInt(1); int x = m.GetInt(2); int y = m.GetInt(3); if (players.ContainsKey(playerId)) { players[playerId].X = x; players[playerId].Y = y; } } break; } case "saved": bot.ChatSayer.Say("World saved."); break; default: Console.WriteLine(m.Type); break; } }