예제 #1
0
        //Return count for PlayerObjects
        private int ExtractPlayerObjectsMessage(PlayerIOClient.Message param)
        {
            int _loc2_ = -1;
            int _loc3_ = -1;
            int _loc4_ = 0;

            while (_loc4_ < param.Count)
            {
                if (param[(UInt32)_loc4_].GetType() == typeof(string) && param.GetString(Convert.ToUInt32(_loc4_)) == "ss")
                {
                    _loc2_ = _loc4_;
                }
                else if (param[(UInt32)_loc4_].GetType() == typeof(string) && param.GetString(Convert.ToUInt32(_loc4_)) == "se")
                {
                    _loc3_ = _loc4_;
                }
                _loc4_++;
            }
            if (_loc3_ == -1)
            {
                Console.WriteLine("Settings end is missing.");
            }
            if (_loc2_ == -1)
            {
                return(_loc3_);
            }
            return(_loc3_);
        }
예제 #2
0
        private void ConnectionMessage3ListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            ConnectionMessage1ListView.Select();
            ConnectionMessage1ListView.SelectedItems[0].Selected = true;

            if (ConnectionMessage3ListView.SelectedIndices.Count == 0)
            {
                ConnectionMessage4TextBox.Clear();
            }
            else
            {
                PlayerIOClient.Message item = this.messages[ConnectionMessage1ListView.SelectedItems[0].Text][ConnectionMessage2ListBox.SelectedIndex].Item2;
                uint index = (uint)ConnectionMessage3ListView.SelectedIndices[0];
                if (item[index].GetType().ToString() == "System.Byte[]")
                {
                    ConnectionMessage4TextBox.Text      = "Byte found, can't convert";
                    ConnectionMessage4TextBox.ForeColor = Color.Red;
                }
                else
                {
                    ConnectionMessage4TextBox.Text      = item[index].ToString();
                    ConnectionMessage4TextBox.ForeColor = SystemColors.WindowText;
                }
            }
        }
예제 #3
0
파일: Form1.cs 프로젝트: SirJosh3917/SeSet
        void c_OnMessage(object sender, PlayerIOClient.Message e)
        {
            switch (e.Type)
            {
            case "init":
                int width  = e.GetInt(18);
                int height = e.GetInt(19);
                edit = e.GetBoolean(14);
                _w   = width;
                _h   = height;
                x.Send("init2");
                break;

            case "init2":
                //start building
                x.Send("say", "Ready to build!");
                if (edit)
                {
                    Build();
                }
                break;

            case "access":
                Build();
                break;
            }
        }
예제 #4
0
        private void Conn_OnMessage(object sender, PlayerIOClient.Message e)
        {
            switch (e.Type)
            {
            case "init":
                chatQueue = new ChatQueue();
                var initEvent = new EEBLInitEvent(chatQueue);
                Bots.ForEach(bot => bot.OnInit(initEvent));
                conn.Send("init2");
                break;

            case "add":
                NamedMessageAdd message = new NamedMessageAdd(new MessageAdd(e));

                EEBLAPI.Player.Player player = new EEBLAPI.Player.Player(message.UniqueUserId);
                player.Id       = message.Id;
                player.Username = message.Username;
                playerHandler.AddPlayer(player);
                playerHandler.PlayerJoin(player, message.SourceMessage);
                break;

            case "left":
                playerHandler.RemovePlayer(
                    playerHandler.GetPlayer(e.GetInt(0))
                    );
                break;
            }
        }
예제 #5
0
        public void OnMessage(object sender, PlayerIOClient.Message e)
        {
            if (e.Type == "init")
            {
                MapFrame = Frame.FromMessage(e, false);
                if (MapFrame != null)
                {
                    if (e.GetUInt(21) == 0)
                    {
                        EEditor.MainForm.userdata.thisColor = Color.Transparent;
                    }
                    else
                    {
                        EEditor.MainForm.userdata.useColor  = true;
                        EEditor.MainForm.userdata.thisColor = UIntToColor(e.GetUInt(21));
                    }

                    var owner = e.GetString(0) == "" ? "Unknown" : e.GetString(0);
                    MainForm.Text = e[1] + " by " + owner + " (" + e[18] + "x" + e[19] + ") - EEditor " + this.ProductVersion;
                    SizeWidth     = MapFrame.Width;
                    SizeHeight    = MapFrame.Height;
                    Connection.Disconnect();
                    Connection.OnMessage -= OnMessage;
                    s.Release();
                    DialogResult = System.Windows.Forms.DialogResult.OK;
                    Close();
                }
                else
                {
                    MessageBox.Show("World's width and height aren't integers. Please report this to our bug tracker.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    s.Release();
                    DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    Close();
                }
            }
            else if (e.Type == "upgrade")
            {
                MessageBox.Show("Game got updated. Please report this to our bug tracker.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                s.Release();
                DialogResult = System.Windows.Forms.DialogResult.Cancel;
                Close();
            }
            else
            {
                messages += 1;
                if (messages == 1)
                {
                    MessageBox.Show(e.GetString(1), e.GetString(0), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    s.Release();
                    DialogResult = System.Windows.Forms.DialogResult.Cancel;
                    Close();
                }

                //if (e.Type != "b" && e.Type != "m" && e.Type != "hide" && e.Type != "show")Console.WriteLine(e.ToString());
            }
        }
예제 #6
0
 void handlemessage(object sender, PlayerIOClient.Message m)
 {
     msgList.Add(m);
     Debug.Log(m.Type);
     if (m.Type.Equals("TurnEnd") || m.Type.Equals("PlayerName") || m.Type.Equals("EnemyName"))
     {
         Debug.Log("ProcessMessages : " + m.Type);
         ProcessMessages();
     }
 }
예제 #7
0
    void connection_OnMessage(object sender, PlayerIOClient.Message e)
    {
        // handle incoming messages
        switch (e.Type)
        {
        // server sent us our ID
        case "SetID":
            NetworkUtils.localPlayerID = e.GetInt(0);
            break;

        // add a player to list of players in the room
        case "UserJoined":
            NetworkUtils.PlayersInRoom.Add(e.GetInt(0), e.GetString(1));
            break;

        // remove player from list of players
        case "UserLeft":
            NetworkUtils.PlayersInRoom.Remove(e.GetInt(0));
            //clean up this player's bots
            foreach (int botID in BotInfo.botMap.Keys)
            {
                Destroy(BotInfo.botMap[botID].gameObject);
            }
            break;

        // spawn a bot
        case "OnBotSpawned":
            break;

        // update a bot
        case "UpdateBot":
            break;

        // destroy a bot
        case "BotDied":
            break;

        // local player got a kill
        case "GotKill":
            break;

        // one of local player's bots took damage
        case "TookDamage":
            break;
        }
    }
예제 #8
0
 private void Button1_Click(object sender, EventArgs e)
 {
     if (!protocol.ContainsKey(ConnectionMessage1ListView.SelectedItems[0].Text))
     {
         Protocol prtc1 = new Protocol()
         {
             Data = new Dictionary <int, JToken>()
         };
         prtc1.Data.Clear();
         PlayerIOClient.Message item = this.messages[ConnectionMessage1ListView.SelectedItems[0].Text][ConnectionMessage2ListBox.SelectedIndex].Item2;
         for (int i = 0; i < item.Count; i++)
         {
             prtc1.Data.Add(i, item[(uint)i].GetType().ToString());
         }
         protocol.Add(ConnectionMessage1ListView.SelectedItems[0].Text, prtc1);
     }
     File.WriteAllText(pathtoprotocol, JsonConvert.SerializeObject(protocol, Newtonsoft.Json.Formatting.Indented));
 }
예제 #9
0
        private static void onMessage(object sender, PlayerIOClient.Message m)
        {
            //Init is the only event we really care about for this bot.
            switch (m.Type)
            {
            case "init":
            {
                WorldKey = derot(m.GetString(5));
                //WorldWidth = m.GetInt (18);
                WorldHeight = m.GetInt(19);
            }
                return;
                //Definitely not a smart thing to allow others to do...

                /*
                 * case "say":
                 *      {
                 *              if (m.GetString (1).Substring (0, 6) != "!midi ") {
                 *                      break;
                 *              }
                 *              try {
                 *                      for (int i = 0; i < 16; ++i) {
                 *                              chans [i] = true;
                 *                      }
                 *                      Midi mid = new Midi ();
                 *                      if (!mid.Read (m.GetString (1).Substring (6))) {
                 *                              Console.WriteLine ("Failed to load file. Reason:");
                 *                              Console.WriteLine (mid.LastError);
                 *                      }
                 *                      mid.Rewind ();
                 *                      Worker args = new Worker(MyConnection, mid);
                 *                      System.Threading.Thread t = new System.Threading.Thread( args.DoWork );
                 *                      t.Start();
                 *
                 *              } catch (Exception e) {
                 *                      Console.WriteLine (e.Message);
                 *              }
                 *      }
                 *      break;
                 */
            }
        }
예제 #10
0
 void WD_parser(PlayerIOClient.Message m, uint c)
 {
     bl = new int[2][][];
     for (int l = 0; l < 2; l++)
     {
         bl[l] = new int[worldWidth][];
         for (int x = 0; x < worldWidth; x++)
         {
             bl[l][x] = new int[worldHeight];
         }
     }
     while (c < m.Count)
     {
         int    bid = m.GetInt(c);
         int    l   = m.GetInt(c + 1);
         byte[] pX  = m.GetByteArray(c + 2);
         byte[] pY  = m.GetByteArray(c + 3);
         for (int n = 0; n < pX.Length; n += 2)
         {
             int x = pX[n] << 8 | pX[n + 1],
                 y = pY[n] << 8 | pY[n + 1];
             bl[l][x][y] = bid;
         }
         if (bid == 43 || bid == 77 || bid == 83 || bid == 1000)
         {
             c += 5;
         }
         else if (bid == 242)
         {
             c += 7;
         }
         else
         {
             c += 4;
         }
     }
 }
예제 #11
0
        private void OnMessage(object sender, Message m)
        {
            switch (m.Type)
            {
            case "timeout":
                MessageBox.Show("timeout error");
                Environment.Exit(0);
                break;

            case "name":
                XDDDD();    //im sorry
                richTextBox1.SafeInvoke(() => richTextBox1.AppendText("Connected!", Color.ForestGreen));
                button2.SafeInvoke(() => button2.Text = m.GetString(0));
                self = m.GetString(0);
                break;

            case "rename":
                if (m.GetString(0) == self)
                {
                    self = m.GetString(1);
                    button2.SafeInvoke(() => button2.Text = m.GetString(1));
                }
                else
                {
                    users.Remove(m.GetString(0));
                    users.Add(m.GetString(1));
                    UpdateOnline();
                }
                UpdateChat(String.Format("{0} is now {1}.", m.GetString(0), m.GetString(1)), Color.Yellow);
                break;

            case "oldsay":
                UpdateChat(String.Format("{0}: {1}", m.GetString(0), m.GetString(1)), Color.Gray);
                break;

            case "say":
                UpdateChat(String.Format("{0}: {1}", m.GetString(0), m.GetString(1)), Color.White);
                break;

            case "me":
                UpdateChat(String.Format("* {0} {1}", m.GetString(0), m.GetString(1)), Color.YellowGreen);
                break;

            case "system":
                UpdateChat(m.GetString(0), Color.OrangeRed);
                break;

            case "roll":
                UpdateChat(String.Format("* {0} rolled {1}. [{2}-{3}]", m.GetString(0), m.GetInt(1), m.GetInt(2), m.GetInt(3)), Color.LightSeaGreen);
                break;

            case "online":
                for (uint i = 0; i < m.Count; i++)
                {
                    if (!users.Contains(m.GetString(i)))
                    {
                        users.Add(m.GetString(i));
                    }
                }
                UpdateOnline();
                break;

            case "add":
                users.Add(m.GetString(0));
                UpdateChat(String.Format("{0} has joined the chat.", m.GetString(0)), Color.CadetBlue);
                UpdateOnline();
                break;

            case "left":
                users.Remove(m.GetString(0));
                UpdateChat(String.Format("{0} has left the chat.", m.GetString(0)), Color.CadetBlue);
                UpdateOnline();
                break;
            }
        }
예제 #12
0
 void handlemessage(object sender, PlayerIOClient.Message m)
 {
     msgList.Add(m);
 }
예제 #13
0
 void connection_OnMessage(object sender, PlayerIOClient.Message e)
 {
     // handle incoming messages
 }
예제 #14
0
 void OnMsg(object sender, PlayerIOClient.Message m)
 {
     if (m.Type == "init")
     {
         key           = getkey(m.GetString(3));
         isOwner       = m.GetBoolean(9);
         worldWidth    = m.GetInt(10);
         worldHeight   = m.GetInt(11);
         nu_xp.Maximum = worldWidth;
         nu_yp.Maximum = worldHeight;
         WD_parser(m, 13);
         con.Send(key + 'f', 1);
         con.Send("access", tb_code.Text);
         return;
     }
     if (m.Type == "access")
     {
         MessageBox.Show("Got Access.");
         return;
     }
     if (m.Type == "lostaccess")
     {
         if (!isOwner)
         {
             running = false;
             MessageBox.Show("Lost Access.");
         }
         return;
     }
     if (m.Type == "clear")
     {
         worldWidth  = m.GetInt(0);
         worldHeight = m.GetInt(1);
         bl          = new int[2][][];
         for (int l = 0; l < 2; l++)
         {
             bl[l] = new int[worldWidth][];
             for (int x = 0; x < worldWidth; x++)
             {
                 bl[l][x] = new int[worldHeight];
             }
         }
         for (int x = 0; x < worldWidth; x++)
         {
             bl[0][x][0] = 9;
             bl[0][x][worldHeight - 1] = 9;
         }
         for (int y = 1; y < worldHeight - 1; y++)
         {
             bl[0][0][y] = 9;
             bl[0][worldWidth - 1][y] = 9;
         }
         return;
     }
     if (m.Type == "reset")
     {
         WD_parser(m, 0);
         return;
     }
     if (bl == null)
     {
         return;
     }
     if (m.Type == "b")
     {
         bl[m.GetInt(0)][m.GetInt(1)][m.GetInt(2)] = m.GetInt(3);
         return;
     }
     if (m.Type == "bc" || m.Type == "bs" || m.Type == "lb" || m.Type == "pt")
     {
         bl[0][m.GetInt(0)][m.GetInt(1)] = m.GetInt(2);
         return;
     }
 }
예제 #15
0
파일: Form1.cs 프로젝트: EETomahawk/TagBot
        private void con_OnMessage(object sender, Message m)
        {
            switch (m.Type)
            {
                #region Init
            case "init":
                #region Owner-only
                if (!m.GetBoolean(15))
                {
                    con.Disconnect();
                    MessageBox.Show("For this bot to work, it must be the owner of the world.\n\nDisconnected.", "TagBot");
                    return;
                }
                #endregion
                con.Send("init2");
                players.Add(m.GetInt(5), m.GetString(13));
                lbStatus.Text = "Status: Connected";
                #region Cookie
                if (cbSave.Checked)
                {
                    Properties.Settings.Default.Username = tbUsername.Text;
                    Properties.Settings.Default.Password = tbPassword.Text;
                    Properties.Settings.Default.RoomID   = tbRoomID.Text;
                    Properties.Settings.Default.Save();
                }
                #endregion
                break;

                #endregion
                #region Add/Left
            case "add":
                players.Add(m[0], m.GetString(1));
                teams.Add(m.GetInt(0), m.GetInt(16));
                break;

            case "left":
                players.Remove(m[0]);
                teams.Remove(m.GetInt(0));
                break;

                #endregion
                #region Team
            case "team":
                lastTeam           = teams[m.GetInt(0)];
                teams[m.GetInt(0)] = m.GetInt(1);
                if (lastTeam == cbTeam.SelectedIndex)
                {
                    con.Send("say", $"/reffect {players[m.GetInt(0)]} curse");
                }
                break;

                #endregion
                #region Say
            case "say":
                if (prefixes.Contains(m.GetString(1)[0]))
                {
                    switch (m.GetString(1).Substring(1).ToLower())
                    {
                        #region bot
                    case "bot":
                        con.Send("say", "This is TagBot, created by Tomahawk.");
                        Thread.Sleep(600);
                        break;

                        #endregion
                        #region download
                    case "download":
                        con.Send("say", "TagBot forum thread: https://forums.everybodyedits.com/viewtopic.php?id=42162");
                        Thread.Sleep(600);
                        break;

                        #endregion
                        #region help
                    case "help":
                        con.Send("say", $"Commands: {string.Join("  ", commands)}");
                        Thread.Sleep(600);
                        break;
                        #endregion
                    }
                }
                break;
                #endregion
            }
        }
예제 #16
0
        void OnMessage(object sender, PlayerIOClient.Message e)
        {
            if (e.Type == "b")
            {
                if (botid != (int)e.GetInt(4) && MainForm.userdata.ignoreplacing)
                {
                    if (e.GetInt(0) == 0)
                    {
                        frames[0].Foreground[e.GetInt(2), e.GetInt(1)]   = e.GetInt(3);
                        remoteFrame.Foreground[e.GetInt(2), e.GetInt(1)] = e.GetInt(3);
                    }
                    else
                    {
                        frames[0].Background[e.GetInt(2), e.GetInt(1)]   = e.GetInt(3);
                        remoteFrame.Background[e.GetInt(2), e.GetInt(1)] = e.GetInt(3);

                        /*frames[0].Foreground[e.GetInt(2), e.GetInt(1)] = 0;
                         * remoteFrame.Foreground[e.GetInt(2), e.GetInt(1)] = 0;
                         */
                    }
                    ++Gcurrent1;
                    restart = true;
                }
                else
                {
                    int layer = e.GetInt(0), x = e.GetInt(1), y = e.GetInt(2), id = e.GetInt(3);
                    if (layer == 0)
                    {
                        remoteFrame.Foreground[y, x] = id;
                    }
                    else
                    {
                        remoteFrame.Background[y, x] = id;
                    }
                    ++Gcurrent;
                    ++Gcurrent1;
                    int value = Gcurrent1;
                    OnStatusChanged("Uploading blocks to level. (Total: " + value + "/" + firstFrame.Count + ")", DateTime.MinValue, false, Gtotal, Gcurrent);
                    if (Convert.ToDouble(Gcurrent1) <= pb.Maximum && Convert.ToDouble(Gcurrent1) >= pb.Minimum)
                    {
                        if (pb.InvokeRequired)
                        {
                            pb.Invoke((MethodInvoker) delegate { pb.Value = Gcurrent1; });
                        }
                        TaskbarProgress.SetValue(afHandle, Gcurrent1, firstFrame.Count);
                    }
                }
            }
            else if (e.Type == "br")
            {
                if (botid != (int)e.GetInt(5) && MainForm.userdata.ignoreplacing)
                {
                    frames[0].Foreground[e.GetInt(1), e.GetInt(0)]   = e.GetInt(2);
                    frames[0].BlockData[e.GetInt(1), e.GetInt(0)]    = e.GetInt(3);
                    remoteFrame.Foreground[e.GetInt(1), e.GetInt(0)] = e.GetInt(2);
                    remoteFrame.BlockData[e.GetInt(1), e.GetInt(0)]  = e.GetInt(3);
                    ++Gcurrent1;
                    restart = true;
                }
                else
                {
                    int x = e.GetInt(0), y = e.GetInt(1);
                    remoteFrame.Foreground[y, x] = e.GetInt(2);
                    remoteFrame.BlockData[y, x]  = e.GetInt(3);
                    ++Gcurrent;
                    ++Gcurrent1;
                    int value = Gcurrent1;
                    OnStatusChanged("Uploading rotatable blocks to level. (Total: " + value + "/" + firstFrame.Count + ")", DateTime.MinValue, false, Gtotal, Gcurrent);
                    if (Convert.ToDouble(Gcurrent1) <= pb.Maximum && Convert.ToDouble(Gcurrent1) >= pb.Minimum)
                    {
                        if (pb.InvokeRequired)
                        {
                            pb.Invoke((MethodInvoker) delegate { pb.Value = Gcurrent1; });
                        }
                        TaskbarProgress.SetValue(afHandle, Gcurrent1, firstFrame.Count);
                    }
                }
            }
            else if (e.Type == "wp")
            {
                if (botid != (int)e.GetInt(4) && MainForm.userdata.ignoreplacing)
                {
                    frames[0].Foreground[e.GetInt(1), e.GetInt(0)]   = e.GetInt(2);
                    frames[0].BlockData3[e.GetInt(1), e.GetInt(0)]   = e.GetString(3);
                    remoteFrame.Foreground[e.GetInt(1), e.GetInt(0)] = e.GetInt(2);
                    remoteFrame.BlockData3[e.GetInt(1), e.GetInt(0)] = e.GetString(3);
                    ++Gcurrent1;
                    restart = true;
                }
                else
                {
                    int x = e.GetInt(0), y = e.GetInt(1);
                    remoteFrame.Foreground[y, x] = e.GetInt(2);
                    remoteFrame.BlockData3[y, x] = e.GetString(3);
                    ++Gcurrent;
                    ++Gcurrent1;
                    int value = Gcurrent1;
                    OnStatusChanged("Uploading world portals to level. (Total: " + value + "/" + firstFrame.Count + ")", DateTime.MinValue, false, Gtotal, Gcurrent);
                    if (Convert.ToDouble(Gcurrent1) <= pb.Maximum && Convert.ToDouble(Gcurrent1) >= pb.Minimum)
                    {
                        if (pb.InvokeRequired)
                        {
                            pb.Invoke((MethodInvoker) delegate { pb.Value = Gcurrent1; });
                        }
                        TaskbarProgress.SetValue(afHandle, Gcurrent1, firstFrame.Count);
                    }
                }
            }
            else if (e.Type == "ts")
            {
                if (botid != (int)e.GetInt(5) && MainForm.userdata.ignoreplacing)
                {
                    frames[0].Foreground[e.GetInt(1), e.GetInt(0)]   = e.GetInt(2);
                    frames[0].BlockData3[e.GetInt(1), e.GetInt(0)]   = e.GetString(3);
                    frames[0].BlockData[e.GetInt(1), e.GetInt(0)]    = e.GetInt(4);
                    remoteFrame.Foreground[e.GetInt(1), e.GetInt(0)] = e.GetInt(2);
                    remoteFrame.BlockData3[e.GetInt(1), e.GetInt(0)] = e.GetString(3);
                    remoteFrame.BlockData[e.GetInt(1), e.GetInt(0)]  = e.GetInt(4);
                    ++Gcurrent1;
                    restart = true;
                }
                else
                {
                    int x = e.GetInt(0), y = e.GetInt(1);
                    remoteFrame.Foreground[y, x] = e.GetInt(2);
                    remoteFrame.BlockData3[y, x] = e.GetString(3);
                    remoteFrame.BlockData[y, x]  = e.GetInt(4);
                    ++Gcurrent;
                    ++Gcurrent1;
                    int value = Gcurrent1;
                    OnStatusChanged("Uploading signs to level. (Total: " + value + "/" + firstFrame.Count + ")", DateTime.MinValue, false, Gtotal, Gcurrent);
                    if (Convert.ToDouble(Gcurrent1) <= pb.Maximum && Convert.ToDouble(Gcurrent1) >= pb.Minimum)
                    {
                        if (pb.InvokeRequired)
                        {
                            pb.Invoke((MethodInvoker) delegate { pb.Value = Gcurrent1; });
                        }
                        TaskbarProgress.SetValue(afHandle, Gcurrent1, firstFrame.Count);
                    }
                }
            }
            else if (e.Type == "bc")
            {
                if (botid != (int)e.GetInt(4) && MainForm.userdata.ignoreplacing)
                {
                    frames[0].Foreground[e.GetInt(1), e.GetInt(0)]   = e.GetInt(2);
                    frames[0].BlockData[e.GetInt(1), e.GetInt(0)]    = e.GetInt(3);
                    remoteFrame.Foreground[e.GetInt(1), e.GetInt(0)] = e.GetInt(2);
                    remoteFrame.BlockData[e.GetInt(1), e.GetInt(0)]  = e.GetInt(3);
                    ++Gcurrent1;
                    restart = true;
                }
                else
                {
                    int x = e.GetInt(0), y = e.GetInt(1);
                    remoteFrame.Foreground[y, x] = e.GetInt(2);
                    remoteFrame.BlockData[y, x]  = e.GetInt(3);
                    ++Gcurrent;
                    ++Gcurrent1;
                    int value = Gcurrent1;
                    OnStatusChanged("Uploading numbered action blocks to level. (Total: " + value + "/" + firstFrame.Count + ")", DateTime.MinValue, false, Gtotal, Gcurrent);
                    if (Convert.ToDouble(Gcurrent1) <= pb.Maximum && Convert.ToDouble(Gcurrent1) >= pb.Minimum)
                    {
                        if (pb.InvokeRequired)
                        {
                            pb.Invoke((MethodInvoker) delegate { pb.Value = Gcurrent1; });
                        }
                        TaskbarProgress.SetValue(afHandle, Gcurrent1, firstFrame.Count);
                    }
                }
            }
            else if (e.Type == "pt")
            {
                if (botid != (int)e.GetInt(6) && MainForm.userdata.ignoreplacing)
                {
                    frames[0].Foreground[e.GetInt(1), e.GetInt(0)]   = e.GetInt(2);
                    frames[0].BlockData[e.GetInt(1), e.GetInt(0)]    = e.GetInt(3);
                    frames[0].BlockData1[e.GetInt(1), e.GetInt(0)]   = e.GetInt(4);
                    frames[0].BlockData2[e.GetInt(1), e.GetInt(0)]   = e.GetInt(5);
                    remoteFrame.Foreground[e.GetInt(1), e.GetInt(0)] = e.GetInt(2);
                    remoteFrame.BlockData[e.GetInt(1), e.GetInt(0)]  = e.GetInt(3);
                    remoteFrame.BlockData1[e.GetInt(1), e.GetInt(0)] = e.GetInt(4);
                    remoteFrame.BlockData2[e.GetInt(1), e.GetInt(0)] = e.GetInt(5);
                    ++Gcurrent1;
                    restart = true;
                }
                else
                {
                    int x = e.GetInt(0);
                    int y = e.GetInt(1);
                    remoteFrame.Foreground[y, x] = e.GetInt(2);
                    remoteFrame.BlockData[y, x]  = e.GetInt(3);
                    remoteFrame.BlockData1[y, x] = e.GetInt(4);
                    remoteFrame.BlockData2[y, x] = e.GetInt(5);
                    ++Gcurrent;
                    ++Gcurrent1;
                    int value = Gcurrent1;
                    OnStatusChanged("Uploading portals to level. (Total: " + value + "/" + firstFrame.Count + ")", DateTime.MinValue, false, Gtotal, Gcurrent);
                    if (Convert.ToDouble(Gcurrent1) <= pb.Maximum && Convert.ToDouble(Gcurrent1) >= pb.Minimum)
                    {
                        if (pb.InvokeRequired)
                        {
                            pb.Invoke((MethodInvoker) delegate { pb.Value = Gcurrent1; });
                        }
                        TaskbarProgress.SetValue(afHandle, Gcurrent1, firstFrame.Count);
                    }
                }
            }
            else if (e.Type == "bs")
            {
                if (botid != (int)e.GetInt(4) && MainForm.userdata.ignoreplacing)
                {
                    frames[0].Foreground[e.GetInt(1), e.GetInt(0)]   = e.GetInt(2);
                    frames[0].BlockData[e.GetInt(1), e.GetInt(0)]    = e.GetInt(3);
                    remoteFrame.Foreground[e.GetInt(1), e.GetInt(0)] = e.GetInt(2);
                    remoteFrame.BlockData[e.GetInt(1), e.GetInt(0)]  = e.GetInt(3);
                    ++Gcurrent1;
                    restart = true;
                }
                else
                {
                    int x = e.GetInt(0);
                    int y = e.GetInt(1);
                    remoteFrame.Foreground[y, x] = e.GetInt(2);
                    remoteFrame.BlockData[y, x]  = e.GetInt(3);
                    ++Gcurrent;
                    ++Gcurrent1;
                    int value = Gcurrent1;
                    OnStatusChanged("Uploading noteblocks to level. (Total: " + value + "/" + firstFrame.Count + ")", DateTime.MinValue, false, Gtotal, Gcurrent);
                    if (Convert.ToDouble(Gcurrent1) <= pb.Maximum && Convert.ToDouble(Gcurrent1) >= pb.Minimum)
                    {
                        if (pb.InvokeRequired)
                        {
                            pb.Invoke((MethodInvoker) delegate { pb.Value = Gcurrent1; });
                        }
                        TaskbarProgress.SetValue(afHandle, Gcurrent1, firstFrame.Count);
                    }
                }
            }
            else if (e.Type == "access")
            {
                passTimer.Dispose();
                locker.Release();
            }
            else if (e.Type == "init")
            {
                botid = e.GetInt(5);
                AnimateForm.editRights = false;
                AnimateForm.saveRights = false;
                AnimateForm.crewEdit   = false;
                AnimateForm.crewWorld  = false;
                remoteFrame            = Frame.FromMessage(e, false);
                conn.Send("init2");
                OnStatusChanged("Connected to the world.", DateTime.MinValue, false, Gtotal, Gcurrent);
                if (frames[0].Width <= remoteFrame.Width && frames[0].Height <= remoteFrame.Height)
                {
                }
                else
                {
                    Gtotal = Gcurrent = pb.Maximum = pb.Value = 1;
                    ModifyProgressBarColor.SetState(pb, 2);
                    TaskbarProgress.SetValue(afHandle, Gcurrent, Gtotal);
                    TaskbarProgress.SetState(afHandle, TaskbarProgress.TaskbarStates.Error);
                    OnStatusChanged("Wrong level size. Please create a level with the size of " + remoteFrame.Width + "x" + remoteFrame.Height + ".", DateTime.MinValue, true, Gtotal, Gcurrent);
                    return;
                }
                if (e.GetBoolean(34))
                {
                    AnimateForm.crewWorld = true;
                    if (e.GetBoolean(14))
                    {
                        AnimateForm.crewEdit = true;
                        if (e.GetBoolean(31))
                        {
                            AnimateForm.saveRights = true;
                            if (MainForm.userdata.useColor)
                            {
                                if (MainForm.userdata.thisColor != Color.Transparent)
                                {
                                    var hex = ColorTranslator.ToHtml(MainForm.userdata.thisColor);
                                    conn.Send("say", "/bgcolor " + hex);
                                }
                                else
                                {
                                    conn.Send("say", "/bgcolor none");
                                }
                            }
                            else
                            {
                                conn.Send("say", "/bgcolor none");
                            }
                        }
                        locker.Release();
                    }
                    else
                    {
                        OnStatusChanged("Crew: You doesn't have edit rights in this world", DateTime.MinValue, true, Gtotal, Gcurrent);
                        return;
                    }
                }

                else if (e.GetString(0) != e.GetString(13))
                {
                    owner = false;
                    if (MainForm.userdata.level.StartsWith("OW") && levelPassword.Length == 0)
                    {
                        if (e.GetBoolean(14))
                        {
                            MainForm.OpenWorld     = true;
                            MainForm.OpenWorldCode = false;
                            locker.Release();
                        }
                        else
                        {
                            MainForm.OpenWorld     = false;
                            MainForm.OpenWorldCode = false;
                            OnStatusChanged("You need a password for this world", DateTime.MinValue, true, Gtotal, Gcurrent);
                            return;
                        }
                    }
                    else if (MainForm.userdata.level.StartsWith("OW") && levelPassword.Length > 0)
                    {
                        if (!e.GetBoolean(14))
                        {
                            MainForm.OpenWorld     = true;
                            MainForm.OpenWorldCode = true;
                            conn.Send("access", levelPassword);
                            passTimer = new System.Threading.Timer(x => OnStatusChanged("Wrong level code. Please enter the right one and retry.", DateTime.MinValue, true, Gtotal, Gcurrent), null, 5000, Timeout.Infinite);
                        }
                        else
                        {
                            MainForm.OpenWorld     = true;
                            MainForm.OpenWorldCode = false;
                            OnStatusChanged("This world isn't password protected", DateTime.MinValue, true, Gtotal, Gcurrent);
                            return;
                        }
                    }
                    else
                    {
                        if (MainForm.userdata.saveWorldCrew)
                        {
                            OnStatusChanged("You are not the owner of this world. You can't save.", DateTime.MinValue, true, Gtotal, Gcurrent);
                            return;
                        }
                        else
                        {
                            if (levelPassword.Length > 0)
                            {
                                Gtotal = Gcurrent = pb.Maximum = pb.Value = 1;
                                ModifyProgressBarColor.SetState(pb, 3);
                                TaskbarProgress.SetValue(afHandle, Gcurrent, Gtotal);
                                TaskbarProgress.SetState(afHandle, TaskbarProgress.TaskbarStates.Paused);
                                conn.Send("access", levelPassword);
                                passTimer = new System.Threading.Timer(x => OnStatusChanged("Wrong level code. Please enter the right one and retry.", DateTime.MinValue, true, Gtotal, Gcurrent), null, 5000, Timeout.Infinite);
                            }
                            else if (e.GetBoolean(14))
                            {
                                AnimateForm.editRights = true;
                                locker.Release();
                            }
                            else
                            {
                                passTimer = new System.Threading.Timer(x => OnStatusChanged("Didn't get edit. Timer stopped.", DateTime.MinValue, true, Gtotal, Gcurrent), null, 20000, Timeout.Infinite);
                            }
                        }
                    }
                }
                else if (e.GetString(0) == e.GetString(13))
                {
                    if (MainForm.userdata.useColor)
                    {
                        if (MainForm.userdata.thisColor != Color.Transparent)
                        {
                            var hex = ColorTranslator.ToHtml(MainForm.userdata.thisColor);
                            conn.Send("say", "/bgcolor " + hex);
                        }
                        else
                        {
                            conn.Send("say", "/bgcolor none");
                        }
                    }
                    else
                    {
                        conn.Send("say", "/bgcolor none");
                    }
                    AnimateForm.editRights = true;
                    AnimateForm.saveRights = true;
                    owner = true;
                    locker.Release();
                }
            }
            else
            {
                switch (e.Type)
                {
                case "info":
                    switch (e[0].ToString())
                    {
                    case "Limit reached":
                        MessageBox.Show(e.GetString(1), e.GetString(0), MessageBoxButtons.OK, MessageBoxIcon.Error);
                        break;
                    }
                    break;
                }
            }
        }
예제 #17
0
        private void onMessage(object sender, PlayerIOClient.Message m)
        {
            switch (m.Type)
            {
            case "init":
            {
                if (isBB)
                {
                    owner    = m.GetString(0);
                    title    = m.GetString(1);
                    worldKey = rot13(m[3].ToString());
                    hasCode  = m.GetBoolean(8);
                    isOwner  = m.GetBoolean(9);
                }
                else
                {
                    owner    = m.GetString(0);
                    title    = m.GetString(1);
                    worldKey = rot13(m[5].ToString());
                    hasCode  = m.GetBoolean(10);
                    isOwner  = m.GetBoolean(11);
                }
                hasCode |= isOwner;
                {
                    string roomData = " - " + title + " ¦ by: " + owner;
                    Program.form1.Invoke(new Action(() =>
                                                    Program.form1.Text = Program.form1.Text.Substring(0, 10) + roomData
                                                    ));

                    Program.console.Invoke(new Action(() =>
                                                      Program.console.Text = Program.console.Text.Substring(0, 7) + roomData
                                                      ));
                }

                break;
            }

            case "say":
            {
                Player player = null;
                lock (playerList)
                {
                    if (playerList.ContainsKey(m.GetInt(0)))
                    {
                        Program.form1.say(playerList[m.GetInt(0)].Name, m.GetString(1));
                    }
                }
                int playerId = m.GetInt(0);
                lock (playerList)
                {
                    player = playerList[playerId];
                }
                BotSystemHandler.onCommand(sender, m.GetString(1).Substring(1), playerId, player, this);
                break;
            }

            case "add":
            {
                Player player = new Player(m);
                lock (playerList)
                {
                    if (!playerList.ContainsKey(m.GetInt(0)))
                    {
                        playerList.Add(m.GetInt(0), player);
                    }
                    else
                    {
                        return;
                    }
                }
                lock (nameList)
                {
                    if (nameList.ContainsKey(player.Name))
                    {
                        nameList.Remove(player.Name);
                    }
                    nameList.Add(player.Name, m.GetInt(0));
                    Program.form1.say("System", player.Name + " joined!");
                    lock (Program.form1.lambdaFunctionQueue)
                    {
                        Program.form1.lambdaFunctionQueue.Enqueue((Form1 form1) =>
                            {
                                lock (Program.form1.listBox_PlayerList.Items)
                                    Program.form1.listBox_PlayerList.Items.Add(player.Name);
                            });
                    }
                }
            }
            break;

            case "left":
            {
                int    tempKey = m.GetInt(0);
                Player player;

                lock (playerList)
                {
                    if (playerList.ContainsKey(tempKey))
                    {
                        player = playerList[tempKey];
                    }
                    else
                    {
                        return;
                    }
                }
                string name = player.Name;
                Program.form1.say("System", name + " left!");
                lock (Program.form1.lambdaFunctionQueue)
                {
                    Program.form1.lambdaFunctionQueue.Enqueue((Form1 form1) =>
                        {
                            lock (Program.form1.listBox_PlayerList.Items)
                                Program.form1.listBox_PlayerList.Items.Remove(name);
                            lock (leftPlayerList)
                            {
                                if (leftPlayerList.ContainsKey(tempKey))
                                {
                                    leftPlayerList.Remove(tempKey);
                                }
                                leftPlayerList.Add(tempKey, (Player)player);
                            }
                            lock (leftNameList)
                            {
                                if (leftNameList.ContainsKey(name))
                                {
                                    leftNameList.Remove(name);
                                }
                                leftNameList.Add(name, tempKey);
                            }
                            lock (playerList)
                            {
                                if (playerList.ContainsKey(tempKey))
                                {
                                    playerList.Remove(tempKey);
                                }
                            }
                            lock (nameList)
                            {
                                if (nameList.ContainsKey(name))
                                {
                                    nameList.Remove(name);
                                }
                            }
                        });
                }
            }
            break;

            case "teleport":
            {
                /*_*/
                Player _loc_5   = null;      //BotPlayer _loc_5 = null;
                int    playerId = m.GetInt(0);
                double xPos     = m.GetInt(1);
                double yPos     = m.GetInt(2);

                /*if (param2 == myid)
                 * {
                 *  player.setPosition(param3, param4);
                 * }
                 * else
                 * {*/
                _loc_5 = playerList[playerId];
                //if (_loc_5)
                //{
                /*_*/
                //_loc_5.setPosition(xPos, yPos);
                //}
                //}
                //return;
            }
            break;

            case "tele":
            {
                int playerId = 0;
                int xPos     = 0;
                int yPos     = 0;

                /*_*//*
                 * Player player = null;//BotPlayer player = null;
                 * bool _loc_2 = m.GetBoolean(0);
                 * uint _loc_3 = 1;
                 * while (_loc_3 < m.Count)
                 * {
                 *
                 *  playerId = m.GetInt(_loc_3);
                 *  xPos = m.GetInt((_loc_3 + 1));
                 *  yPos = m.GetInt(_loc_3 + 2);
                 *  if (playerList.ContainsKey(playerId))
                 *  {
                 *      player = playerList[playerId];
                 *      if (player != null)
                 *      {
                 *          player.x = xPos;
                 *          player.y = yPos;
                 *          player.respawn();
                 *          if (_loc_2)
                 *          {
                 *              player.resetCoins();
                 *              player.purple = false;
                 *          }
                 *      }
                 *      /*if (_loc_4 == myid)
                 *      {
                 *          player.x = _loc_5;
                 *          player.y = _loc_6;
                 *          this.x = -_loc_6;
                 *          this.y = -_loc_6;
                 *          player.respawn();
                 *          if (_loc_2)
                 *          {
                 *              player.resetCoins();
                 *              player.purple = false;
                 *              world.hidePurple = false;
                 *              world.resetCoins();
                 *              world.resetSecrets();
                 *          }
                 *      }* /
                 *  }
                 *  _loc_3 += 3;
                 * }*/
            }        // end function
            break;

            case "kill": //error
            {            /*_*//*
                          * BotPlayer _loc_3 = null;
                          * int playerId = m.GetInt(0);
                          *
                          * if (playerList.ContainsKey(playerId))
                          * {
                          *     _loc_3 = playerList[playerId];
                          *     _loc_3.killPlayer();
                          * }*/
            }
            break;

            case "access":
                hasCode = true;
                Program.console.WriteLine("Code Cracked!");
                //connection.Send("say", "I know the code.");
                break;
                /*_*/

                /*case "m":
                 *  {
                 *      BotPlayer player;
                 *      int playerID;
                 *      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());
                 *      lock (playerList)
                 *      {
                 *          if (playerList.ContainsKey(playerID))
                 *          {
                 *              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;*/
            }

            BotSystemHandler.onMessage(sender, this, m);// OnMessage(sender, m);
        }
예제 #18
0
 public MessageTypeBase(PlayerIOClient.Message message)
 {
     _message = message;
 }
예제 #19
0
    void connection_OnMessage(object sender, PlayerIOClient.Message e)
    {
        // handle incoming messages
        switch (e.Type)
        {
        // server sent us our ID
        case "SetID":
            NetworkUtils.localPlayerID = e.GetInt(0);
            break;

        // add a player to list of players in the room
        case "UserJoined":
            NetworkUtils.PlayersInRoom.Add(e.GetInt(0), e.GetString(1));
            break;

        // remove player from list of players
        case "UserLeft":
            NetworkUtils.PlayersInRoom.Remove(e.GetInt(0));
            //clean up this player's bots
            foreach (ulong botID in BotInfo.botMap.Keys)
            {
                Destroy(BotInfo.botMap[botID].gameObject);
            }
            break;

        // spawn a bot
        case "OnBotSpawned":
            int   spawnedBotOwnerID = e.GetInt(0);
            ulong spawnedBotID      = e.GetULong(1);
            float spawnedBotPosX    = e.GetFloat(2);
            float spawnedBotPosY    = e.GetFloat(3);

            GameObject bot = (GameObject)Instantiate(BotPrefab, new Vector3(spawnedBotPosX, 0f, spawnedBotPosY), Quaternion.identity);
            bot.GetComponent <BotInfo>().OwnerID = spawnedBotOwnerID;
            bot.GetComponent <BotInfo>().BotID   = spawnedBotID;
            break;

        // update a bot
        case "UpdateBot":
            ulong updateBotID     = e.GetULong(0);
            float updatePosX      = e.GetFloat(1);
            float updatePosY      = e.GetFloat(2);
            int   updateBotHealth = e.GetInt(3);

            BotInfo updateBot = BotInfo.botMap[updateBotID];
            updateBot.transform.position = new Vector3(updatePosX, 0f, updatePosY);
            updateBot.SendMessage("SetHealth", updateBotHealth, SendMessageOptions.DontRequireReceiver);
            break;

        // destroy a bot
        case "BotDied":
            // kill bot
            ulong killedBotID = e.GetULong(0);

            BotInfo killedBot = BotInfo.botMap[killedBotID];
            if (killedBot.IsMine)
            {
                // increment lost bots
                NetworkUtils.playerObject.Set("Deaths", NetworkUtils.playerObject.GetInt("Deaths") + 1);
            }

            // destroy bot obj
            GameObject.Destroy(killedBot);
            break;

        // local player got a kill
        case "GotKill":
            // increment kills
            NetworkUtils.playerObject.Set("Kills", NetworkUtils.playerObject.GetInt("Kills") + 1);
            break;

        // one of local player's bots took damage
        case "TookDamage":
            Debug.Log("Taking damage!");
            break;
        }
    }
예제 #20
0
        private void ConnectionMessage2ListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            ConnectionMessage3ListView.Items.Clear();
            ConnectionMessage4TextBox.Clear();
            ConnectionMessage1ListView.Select();
            if (ConnectionMessage2ListBox.SelectedIndex != -1)
            {
                PlayerIOClient.Message item = this.messages[ConnectionMessage1ListView.SelectedItems[0].Text][ConnectionMessage2ListBox.SelectedIndex].Item2;
                for (int num = 0; num < item.Count; num += 1)
                {
                    ConnectionMessage3ListView.Items.Add("[" + num + "]").SubItems.Add(item[(uint)num].GetType().ToString());
                    if (protocol.ContainsKey(ConnectionMessage1ListView.SelectedItems[0].Text))
                    {
                        if (protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.ContainsKey(num))
                        {
                            JToken line = protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data[num];
                            if (line.ToString() == item[(uint)num].GetType().ToString())
                            {
                                ConnectionMessage3ListView.Items[num].ForeColor = Color.Green;
                            }
                            else
                            {
                                ConnectionMessage3ListView.Items[num].ForeColor = Color.Red;
                            }
                        }
                        else
                        {
                            ConnectionMessage3ListView.Items[num].ForeColor = Color.DarkBlue;
                        }

                        /*if (item.Count == protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.Count)
                         * {
                         *  JToken line = protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data[num];
                         *
                         *  if (line.ToString() == item[(uint)num].GetType().ToString() && protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.ContainsKey(num))
                         *  {
                         *      ConnectionMessage3ListView.Items[num].ForeColor = Color.Green;
                         *  }
                         *  else
                         *  {
                         *      ConnectionMessage3ListView.Items[num].ForeColor = Color.Red;
                         *  }
                         * }
                         * else
                         * {
                         *  if (item.Count > protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.Count)
                         *  {
                         *      if (num < protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.Count)
                         *      {
                         *          JToken line = protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.Values[num];
                         *          if (line.ToString() == item[(uint)num].GetType().ToString() && protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.ContainsKey(num))
                         *          {
                         *              ConnectionMessage3ListView.Items[num].ForeColor = Color.Green;
                         *          }
                         *          else
                         *          {
                         *              ConnectionMessage3ListView.Items[num].ForeColor = Color.Red;
                         *          }
                         *      }
                         *
                         *      else
                         *      {
                         *          ConnectionMessage3ListView.Items[num].ForeColor = Color.Red;
                         *      }
                         *  }
                         * }
                         * }
                         * /*if (protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.IndexOf(num))
                         * {
                         * JToken line = protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data[num];
                         *
                         * if (line.ToString() == item[(uint)num].GetType().ToString())
                         * {
                         *  ConnectionMessage3ListView.Items[num].ForeColor = Color.Green;
                         * }
                         * else
                         * {
                         *  ConnectionMessage3ListView.Items[num].ForeColor = Color.Red;
                         * }
                         *
                         * ConnectionMessage3ListView.Items[num].ForeColor = Color.Red;
                         * }
                         * //JToken[] arr = protocol[ConnectionMessage1ListView.SelectedItems[0].Text].Data.ToArray();
                         * /*for (int a = 0; a < arr.Count(); a++)
                         * {
                         * if (arr[a].ToString() == item[(uint)a].GetType().ToString())
                         * {
                         *  Console.WriteLine(item[(uint)a].GetType());
                         * }
                         * }*/
                    }
                }
            }
        }
예제 #21
0
        // the message handler will receive messages here!
        // if any events possible from the protocol, then it will be quickly signed here.
        //
        // EXAMPLE:  if (m.Type == "say")
        //           {
        //               if (m.GetString(1) == "!ping") con.Send("say", "[OpenBot] Pong!");
        //           }
        //
        private void handlemsg(object sender, PlayerIOClient.Message m)
        {
            if (m.Type == "say")
            {
                // add the rest commands with
                //
                // else if (m.GetString(1) == "!mycommand")
                // {
                //     con.Send("say", "[OpenBot] My command! OH NO!");
                // }
                //
                // You can also make a seperate class file to shorten your "else if" condition AKA command script.
                //
                if (m.GetString(1) == "!ping")
                {
                    con.Send("say", "[OpenBot] Pong!");
                    Thread.Sleep(100);
                    con.Send("say", "[OpenBot] ...did I just said that?");
                }
                else if (m.GetString(1) == "!github")
                {
                    con.Send("say", "[OpenBot] Get this bot at https://github.com/skull111-co/openbot");
                }
                else if (m.GetString(1) == "!help")
                {
                    con.Send("say", "[OpenBot] !github, !ping, !help");
                    // Make sure to include your command after implementing to the bot.
                    // If you don't want to, then this is counted as an "easter egg".
                }
                else if (m.GetString(1) == "!ignoresnake")
                {
                    bool enabled = false;
                    foreach (int id in ignoresnakers)
                    {
                        if (id == m.GetInt(0))
                        {
                            enabled = true;
                            List <int> list = new List <int>();
                            list = ignoresnakers.ToList();
                            list.Remove(m.GetInt(0));
                            ignoresnakers = list.ToArray();
                        }
                    }

                    if (!enabled)
                    {
                        List <int> list = new List <int>();
                        list = ignoresnakers.ToList();
                        list.Add(m.GetInt(0));
                        ignoresnakers = list.ToArray();
                        con.Send("pm", m.GetInt(0), "[OpenBot] The snake will ignore you.");
                    }
                    else
                    {
                        con.Send("pm", m.GetInt(0), "[OpenBot] The snake will no longer ignore you.");
                    }
                }
            }
            else if (m.Type == "init")
            {
                con.Send("say", "[OpenBot] Joined!");
                con.Send("init2");                 // joined successfully
            }
            else if (m.Type == "b")
            {
                if (!snake)
                {
                    return;
                }

                foreach (int id in ignoresnakers)
                {
                    if (id == m.GetInt(4))
                    {
                        return;
                    }
                }

                if (m.GetInt(3) == Mineral.Green)
                {
                    Mineral.PlaceBlock(con, Mineral.Colors.Red, m.GetInt(0), m.GetInt(1), m.GetInt(2));
                }
                else if (m.GetInt(3) == Mineral.Red)
                {
                    Mineral.PlaceBlock(con, Mineral.Colors.None, m.GetInt(0), m.GetInt(1), m.GetInt(2));
                }
            }
        }
예제 #22
0
        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;
            }
        }
예제 #23
0
 void HandleMessage(object sender, PlayerIOClient.Message message)
 {
     messages.Add(message);
 }
예제 #24
0
파일: Room.cs 프로젝트: ostkaka0/Ostbot2_1
        public override void onMessage(object sender, OstBot ostBot, PlayerIOClient.Message m)
        {
            //try
            //{
            switch (m.Type)
            {
            case "init":
                bool isOwner;
                if (ostBot.isBB)
                {
                    //worldKey = rot13(m[3].ToString());
                    //botPlayerID = m.GetInt(6);
                    width  = m.GetInt(10);
                    height = m.GetInt(11);
                    //hasCode = m.GetBoolean(8);
                    isOwner = m.GetBoolean(9);
                }
                else
                {
                    //worldKey = rot13(m[5].ToString());
                    //botPlayerID = m.GetInt(6);
                    width  = m.GetInt(12);
                    height = m.GetInt(13);
                    //hasCode = m.GetBoolean(10);
                    isOwner = m.GetBoolean(11);
                }


                if (isOwner)
                {
                    BlockDrawer(ostBot);
                }

                lock (blockMap)
                {
                    for (int l = 0; l < 2; l++)
                    {
                        blockMap[l] = new List <Block> [width, height];

                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                blockMap[l][x, y] = new List <Block>();
                            }
                        }
                    }
                }

                LoadMap(m, 18);
                break;

            case "reset":

                lock (blockMap)
                {
                    for (int l = 0; l < 2; l++)
                    {
                        blockMap[l] = new List <Block> [width, height];

                        for (int x = 0; x < width; x++)
                        {
                            for (int y = 0; y < height; y++)
                            {
                                blockMap[l][x, y] = new List <Block>();
                            }
                        }
                    }
                }
                LoadMap(m, 0);
                break;

            case "access":
                Thread.Sleep(5);
                BlockDrawer(ostBot);
                break;

            case "b":
            {
                Block  block;
                Player placer = null;

                while (blockMap == null)
                {
                    Thread.Sleep(5);
                }

                while (blockMap[m.GetInt(0)] == null)
                {
                    Thread.Sleep(5);
                }

                Block newBlock = new Block(m, ostBot);

                lock (blockMap)
                    blockMap[m.GetInt(0)][m.GetInt(1), m.GetInt(2)].Add(newBlock);

                if (m.Count >= 5)
                {
                    block = Block.CreateBlock(m.GetInt(0), m.GetInt(1), m.GetInt(2), m.GetInt(3), newBlock.placer);
                }
                else
                {
                    block = Block.CreateBlock(m.GetInt(0), m.GetInt(1), m.GetInt(2), m.GetInt(3), null);
                }

                OnBlockDraw(block);
            }
            break;

            case "bc":     // bc, bs, pt, lb, br
            {
                Block block;

                while (blockMap == null)
                {
                    Thread.Sleep(5);
                }

                while (blockMap[0] == null)
                {
                    Thread.Sleep(5);
                }

                block = new Block(m, ostBot);

                lock (blockMap)
                    blockMap[0][m.GetInt(0), m.GetInt(1)].Add(block);

                OnBlockDraw(block);
            }
            break;

            case "bs":
                goto case "bc";

            case "pt":
                goto case "bc";

            case "lb":
                goto case "bc";

            case "br":
                goto case "bc";

            case "clear":
            {
                //Redstone.ClearLists();
                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        for (int i = 0; i < blockMap.Length; i++)
                        {
                            blockMap[i][x, y].Add(Block.CreateBlock(0, x, y, 0, null));
                        }
                    }
                }
                DrawBorder();
            }
            break;
            }
            //}
            //catch (Exception e)
            //{
            // ostBot.shutdown();
            //throw e;
            //}
        }