User() public static method

public static User ( string username, int usermode, string realname ) : string
username string
usermode int
realname string
return string
Exemplo n.º 1
0
            // runs in its own thread, started from Connect()
            void IoThread()
            {
                string outputLine = "";

                lastMessageSent = DateTime.UtcNow;

                do
                {
                    try {
                        ActualBotNick = desiredBotNick;
                        reconnect     = false;
                        Logger.Log(LogType.IRC,
                                   "Connecting to {0}:{1} as {2}",
                                   hostName, port, ActualBotNick);
                        Connect();

                        // register
                        Send(IRCCommands.User(ActualBotNick, 8, ConfigKey.ServerName.GetString()));
                        Send(IRCCommands.Nick(ActualBotNick));

                        while (isConnected && !reconnect)
                        {
                            Thread.Sleep(10);

                            if (localQueue.Length > 0 &&
                                DateTime.UtcNow.Subtract(lastMessageSent).TotalMilliseconds >= SendDelay &&
                                localQueue.Dequeue(ref outputLine))
                            {
                                writer.Write(outputLine + "\r\n");
                                lastMessageSent = DateTime.UtcNow;
                                writer.Flush();
                            }

                            if (OutputQueue.Length > 0 &&
                                DateTime.UtcNow.Subtract(lastMessageSent).TotalMilliseconds >= SendDelay &&
                                OutputQueue.Dequeue(ref outputLine))
                            {
                                writer.Write(outputLine + "\r\n");
                                lastMessageSent = DateTime.UtcNow;
                                writer.Flush();
                            }

                            if (client.Client.Available > 0)
                            {
                                string line = reader.ReadLine();
                                if (line == null)
                                {
                                    break;
                                }
                                HandleMessage(line);
                            }
                        }
                    } catch (SocketException) {
                        Logger.Log(LogType.Warning, "IRC: Disconnected. Will retry in {0} seconds.",
                                   ReconnectDelay / 1000);
                        reconnect = true;
                    } catch (IOException) {
                        Logger.Log(LogType.Warning, "IRC: Disconnected. Will retry in {0} seconds.",
                                   ReconnectDelay / 1000);
                        reconnect = true;
#if !DEBUG
                    } catch (Exception ex) {
                        Logger.Log(LogType.Error, "IRC: {0}", ex);
                        reconnect = true;
#endif
                    }

                    if (reconnect)
                    {
                        Thread.Sleep(ReconnectDelay);
                    }
                } while(reconnect);
            }
Exemplo n.º 2
0
            // runs in its own thread, started from Connect()
            void IoThread()
            {
                string outputLine = "";

                lastMessageSent = DateTime.UtcNow;

                do
                {
                    try
                    {
                        ActualBotNick = desiredBotNick;
                        reconnect     = false;
                        Logger.Log(LogType.SystemActivity,
                                   "Connecting to LegendCraft Global Chat as {2}",
                                   hostName, port, ActualBotNick);
                        if (ActualBotNick == "Custom Minecraft Server (LegendCraft)")
                        {
                            Logger.Log(LogType.Error, "You must set a server name to connect to global chat.");
                            reconnect = false;
                            DisconnectThread();
                        }

                        else
                        {
                            Connect();
                        }


                        // register
                        Send(IRCCommands.User(ActualBotNick, 8, ConfigKey.ServerName.GetString()));
                        Send(IRCCommands.Nick(ActualBotNick));

                        while (isConnected && !reconnect)
                        {
                            Thread.Sleep(10);

                            if (localQueue.Count > 0 &&
                                DateTime.UtcNow.Subtract(lastMessageSent).TotalMilliseconds >= SendDelay &&
                                localQueue.TryDequeue(out outputLine))
                            {
                                writer.Write(outputLine + "\r\n");
                                lastMessageSent = DateTime.UtcNow;
                                writer.Flush();
                            }

                            if (OutputQueue.Count > 0 &&
                                DateTime.UtcNow.Subtract(lastMessageSent).TotalMilliseconds >= SendDelay &&
                                OutputQueue.TryDequeue(out outputLine))
                            {
                                writer.Write(outputLine + "\r\n");
                                lastMessageSent = DateTime.UtcNow;
                                writer.Flush();
                            }

                            if (client.Client.Available > 0)
                            {
                                string line = reader.ReadLine();
                                if (line == null)
                                {
                                    break;
                                }
                                HandleMessage(line);
                            }
                        }
                    }
                    catch (SocketException)
                    {
                        Logger.Log(LogType.Warning, "GlobalChat: Socket Error. Disconnected. Will retry in {0} seconds.",
                                   ReconnectDelay / 1000);
                        reconnect = true;
                    }
                    catch (IOException)
                    {
                        Logger.Log(LogType.Warning, "GlobalChat: IO Error. Disconnected. Will retry in {0} seconds.",
                                   ReconnectDelay / 1000);
                        reconnect = true;
#if !DEBUG
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogType.Error, "GlobalChat: {0}", ex);
                        reconnect = true;
#endif
                    }

                    if (reconnect)
                    {
                        Thread.Sleep(ReconnectDelay);
                    }
                } while (reconnect);
            }