public void Disconnect(string reason)
 {
     if (Connected)
         connection.Disconnect();
     subBotHandler.onDisconnect(reason);
     if (chatSayer != null)
     {
         lock (chatSayer)
         {
             chatSayer.onDisconnect();
             chatSayer = null;
         }
     }
 }
        public bool Connect(string roomId)
        {
            if (LoggedIn)
            {
                client.Multiplayer.CreateJoinRoom(
                    roomId,
                    "Everybodyedits190",
                    true,
                    null,
                    null,
                    delegate(PlayerIOClient.Connection tempConnection)
                    {
                        connection = tempConnection;
                        connection.Send("init");
                        connection.AddOnDisconnect(new DisconnectEventHandler(onDisconnect));
                        connection.AddOnMessage(new MessageReceivedEventHandler(onMessage));

                        chatSayer = new ChatSayer(this);

                        subBotHandler.onConnect();

                        SafeInvoke.Invoke(mainForm, new Action(() => { mainForm.onConnectFinished(true); }));

                    },
                    delegate(PlayerIOError tempError)
                    {
                        SafeInvoke.Invoke(mainForm, new Action(() => { mainForm.onConnectFinished(false); }));
                        MessageBox.Show(tempError.ToString());
                    });
                return true;
            }
            return false;
        }