Exemple #1
0
        public void CloseSlave()
        {
            try
            {
                if (c_Connected)
                {
                    BroadcastSystem(General.Local(290));
                }

                c_Connected  = false;
                c_Connecting = false;

                if (c_Slave != null)
                {
                    c_Slave.Close();
                }

                foreach (Data data in Data.Datas.Values)
                {
                    if (data.Mobile.HasGump(typeof(MultiGump)))
                    {
                        GumpPlus.RefreshGump(data.Mobile, typeof(MultiGump));
                    }
                }
            }
            catch
            {
                Errors.Report("Error disconnecting slave.");
                //Console.WriteLine(e.Message);
                //Console.WriteLine(e.Source);
                //Console.WriteLine(e.StackTrace);
            }
        }
Exemple #2
0
        private void BeginReceive()
        {
            try
            {
                BroadcastSystem(General.Local(289));

                byte[] msg = System.Text.Encoding.ASCII.GetBytes("    " + Server.Misc.ServerList.ServerName);

                c_Slave.Send(msg, 0, msg.Length, SocketFlags.None);

                c_Connected  = true;
                c_Connecting = false;

                WaitForData(c_Slave);

                foreach (Data data in Data.Datas.Values)
                {
                    if (data.Mobile.HasGump(typeof(MultiGump)))
                    {
                        GumpPlus.RefreshGump(data.Mobile, typeof(MultiGump));
                    }
                }
            }
            catch
            {
                Errors.Report("Error opening stream for slave.");
                //Console.WriteLine(e.Message);
                //Console.WriteLine(e.StackTrace);
            }
        }
Exemple #3
0
        private void TimerFail()
        {
            if (!c_Connecting || c_Connected)
            {
                return;
            }

            c_Connecting = false;
            BroadcastSystem("IRC connection attempt timed out.");

            try
            {
                if (c_Thread != null)
                {
                    c_Thread.Abort();
                }
            }
            catch
            {
            }

            c_Thread = null;

            foreach (Data data in Data.Datas.Values)
            {
                if (data.Mobile.HasGump(typeof(IrcGump)))
                {
                    GumpPlus.RefreshGump(data.Mobile, typeof(IrcGump));
                }
            }
        }
Exemple #4
0
        public void Disconnect(bool reconn)
        {
            try
            {
                if (c_Connected)
                {
                    BroadcastSystem(General.Local(110));
                }

                c_Connected  = false;
                c_Connecting = false;

                if (c_Thread != null)
                {
                    try { c_Thread.Abort(); }
                    catch { }
                    c_Thread = null;
                }
                if (c_Reader != null)
                {
                    c_Reader.Close();
                }
                if (c_Writer != null)
                {
                    c_Writer.Close();
                }
                if (c_Tcp != null)
                {
                    c_Tcp.Close();
                }

                if (reconn)
                {
                    Reconnect();
                }

                foreach (Data data in Data.Datas.Values)
                {
                    if (data.Mobile.HasGump(typeof(IrcGump)))
                    {
                        GumpPlus.RefreshGump(data.Mobile, typeof(IrcGump));
                    }
                }
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(268), e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #5
0
        private void ConnectStream()
        {
            try
            {
                c_Connecting   = true;
                c_ConnectTimer = Server.Timer.DelayCall(TimeSpan.FromSeconds(30), new Server.TimerCallback(TimerFail));
                c_LastPong     = DateTime.Now;

                c_Reader = new StreamReader(c_Tcp.GetStream(), System.Text.Encoding.Default);
                c_Writer = new StreamWriter(c_Tcp.GetStream(), System.Text.Encoding.Default);

                BroadcastSystem(General.Local(107));

                SendMessage(String.Format("USER {0} 1 * :Hello!", Data.IrcNick));
                SendMessage(String.Format("NICK {0}", Data.IrcNick));

                c_Thread = new Thread(new ThreadStart(ReadStream));
                c_Thread.Start();

                Server.Timer.DelayCall(TimeSpan.FromSeconds(15.0), new Server.TimerCallback(Names));

                foreach (Data data in Data.Datas.Values)
                {
                    if (data.Mobile.HasGump(typeof(IrcGump)))
                    {
                        GumpPlus.RefreshGump(data.Mobile, typeof(IrcGump));
                    }
                }
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(266), e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Source);
                Console.WriteLine(e.StackTrace);
            }
        }
Exemple #6
0
        private void HandleInput(string str)
        {
            try
            {
                if (str == null)
                {
                    return;
                }

                BroadcastRaw(str);

                if (str.IndexOf("PONG") != -1 || str.IndexOf("PING") != -1)
                {
                    PingPong(str);
                    return;
                }

                if (str.IndexOf("353") != -1)
                {
                    BroadcastRaw(General.Local(109));

                    int index = str.ToLower().IndexOf(Data.IrcRoom.ToLower()) + Data.IrcRoom.Length + 2;

                    if (index == 1)
                    {
                        return;
                    }

                    string strList = str.Substring(index, str.Length - index);

                    string[] strs = strList.Trim().Split(' ');

                    Data.IrcList.Clear();
                    Data.IrcList.AddRange(strs);
                    Data.IrcList.Remove(Data.IrcNick);
                }

                if (str.IndexOf("001") != -1 && c_Connecting)
                {
                    c_Connected  = true;
                    c_Connecting = false;

                    if (c_ConnectTimer != null)
                    {
                        c_ConnectTimer.Stop();
                    }

                    BroadcastSystem(General.Local(108));
                    c_Attempts = 1;

                    SendMessage(String.Format("JOIN {0}", Data.IrcRoom));

                    foreach (Data data in Data.Datas.Values)
                    {
                        if (data.Mobile.HasGump(typeof(IrcGump)))
                        {
                            GumpPlus.RefreshGump(data.Mobile, typeof(IrcGump));
                        }
                    }
                }

                if (str.Length > 300)
                {
                    return;
                }

                if (str.IndexOf("PRIVMSG") != -1)
                {
                    string parOne = str.Substring(1, str.IndexOf("!") - 1);

                    string parThree = str.Substring(str.IndexOf("!") + 1, str.Length - str.IndexOf("!") - (str.Length - str.IndexOf("PRIVMSG")) - 1);

                    int index = 0;

                    index = str.ToLower().IndexOf(Data.IrcRoom.ToLower()) + Data.IrcRoom.Length + 2;

                    if (index == 1)
                    {
                        return;
                    }

                    string parTwo = str.Substring(index, str.Length - index);

                    if (parTwo.IndexOf("ACTION") != -1)
                    {
                        index  = parTwo.IndexOf("ACTION") + 7;
                        parTwo = parTwo.Substring(index, parTwo.Length - index);
                        str    = String.Format("<{0}> {1} {2}", Data.IrcRoom, parOne, parTwo);
                    }
                    else
                    {
                        str = String.Format("<{0}> {1}: {2}", Data.IrcRoom, parOne, parTwo);
                    }

                    Broadcast(parOne, str);

                    if (str.ToLower().IndexOf("!status") != -1 && c_NextStatus < DateTime.Now)
                    {
                        c_NextStatus = DateTime.Now + TimeSpan.FromSeconds(15);
                        s_Connection.SendMessage(String.Format("PRIVMSG {0} : {1}", Data.IrcRoom, Status));
                        BroadcastSystem(Status);
                    }
                }
            }
            catch (Exception e)
            {
                Errors.Report(General.Local(267), e);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Message);
                Console.WriteLine(e.Message);
            }
        }