Exemplo n.º 1
0
 private static void Quit()
 {
     try
     {
         Gaming.Stop();
     }
     catch (Exception e)
     {
         Debug.WriteLine(e);
         if (Debugger.IsAttached)
         {
             Debugger.Break();
         }
     }
     _running = false;
     Trace.WriteLine("###PROCESS QUIT####");
 }
Exemplo n.º 2
0
        private static void XmppOnOnMessage(object sender, Message msg)
        {
            switch (msg.Type)
            {
            case MessageType.normal:
                if (msg.Subject == "hostgame")
                {
                    if (isPaused)
                    {
                        messageQueue.Enqueue(msg);
                        return;
                    }
                    var data = msg.Body.Split(new string[1] {
                        ",:,"
                    }, StringSplitOptions.None);
                    if (data.Length != 5)
                    {
                        return;
                    }
                    var     guid = Guid.Empty;
                    Version ver  = null;
                    if (String.IsNullOrWhiteSpace(data[2]))
                    {
                        return;
                    }
                    var gameName       = data[2];
                    var password       = data[3];
                    var gameActualName = data[4];
                    if (Guid.TryParse(data[0], out guid) && Version.TryParse(data[1], out ver))
                    {
                        var port = Gaming.HostGame(guid, ver, gameName, password, new Lobby.User(msg.From), gameActualName);
                        if (port == -1)
                        {
                            return;
                        }
                        var m = new Message(msg.From, msg.To, MessageType.normal, port.ToString(), "gameready");
                        m.GenerateId();
                        Xmpp.Send(m);
                    }
                }
                else if (msg.Subject == "gamelist")
                {
                    if (isPaused)
                    {
                        messageQueue.Enqueue(msg);
                        return;
                    }
                    var list = Gaming.GetLobbyList().Where(x => x.GameStatus == EHostedGame.StartedHosting);
                    var m    = new Message(msg.From, MessageType.normal, "", "gamelist");
                    m.GenerateId();
                    foreach (var a in list)
                    {
                        m.AddChild(a);
                    }
                    Xmpp.Send(m);
                }
                else if (msg.Subject == "gamestarted")
                {
                    if (isPaused)
                    {
                        messageQueue.Enqueue(msg);
                        return;
                    }
                    int port = -1;
                    if (Int32.TryParse(msg.Body, out port))
                    {
                        Gaming.StartGame(port);
                    }
                }
                break;

            case MessageType.error:
                break;

            case MessageType.chat:
                if (!msg.From.User.Equals("d0c", StringComparison.InvariantCultureIgnoreCase))
                {
                    return;
                }
                if (msg.Body.Equals("pause"))
                {
                    isPaused = true;
                    Console.WriteLine(":::::: PAUSED ::::::");
                    var m = new Message(msg.From, MessageType.chat, "Paused");
                    m.GenerateId();
                    Xmpp.Send(m);
                }
                else if (msg.Body.Equals("unpause"))
                {
                    isPaused = false;
                    Console.WriteLine("Unpausing...");
                    var m = new Message(msg.From, MessageType.chat, "Unpausing");
                    m.GenerateId();
                    Xmpp.Send(m);
                    while (messageQueue.Count > 0)
                    {
                        XmppOnOnMessage(null, messageQueue.Dequeue());
                    }
                    Console.WriteLine(":::::: UNPAUSED ::::::");
                    var m2 = new Message(msg.From, MessageType.chat, "UnPaused");
                    m2.GenerateId();
                    Xmpp.Send(m2);
                }
                break;

            case MessageType.groupchat:
                break;

            case MessageType.headline:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemplo n.º 3
0
        private static void XmppOnOnMessage(object sender, Message msg)
        {
            switch (msg.Type)
            {
            case MessageType.normal:
                if (msg.Subject == "hostgame")
                {
                    var data = msg.Body.Split(new string[1] {
                        ",:,"
                    }, StringSplitOptions.RemoveEmptyEntries);
                    if (data.Length != 3)
                    {
                        return;
                    }
                    var     guid = Guid.Empty;
                    Version ver  = null;
                    if (String.IsNullOrWhiteSpace(data[2]))
                    {
                        return;
                    }
                    var gameName = data[2];
                    if (Guid.TryParse(data[0], out guid) && Version.TryParse(data[1], out ver))
                    {
                        var port = Gaming.HostGame(guid, ver, gameName, "", new Lobby.User(msg.From));
                        if (port == -1)
                        {
                            return;
                        }
                        var m = new Message(msg.From, msg.To, MessageType.normal, port.ToString(), "gameready");
                        m.GenerateId();
                        Xmpp.Send(m);
                        var gameMessage = String.Format(" {0} is hosting a game called '{1}'", msg.From.User, gameName);
                        m = new Message(new Jid("lobby@conference." + ServerPath), msg.To, MessageType.groupchat, gameMessage);
                        //Xmpp.Send(m);
                        //RefreshLists();
                    }
                }
                else if (msg.Subject == "gamelist")
                {
                    //Trace.WriteLine("[Bot]Request GameList: " + msg.From.User);
                    var list = Gaming.GetLobbyList().Where(x => x.GameStatus == EHostedGame.StartedHosting);
                    var m    = new Message(msg.From, MessageType.normal, "", "gamelist");
                    m.GenerateId();
                    foreach (var a in list)
                    {
                        m.AddChild(a);
                    }
                    Xmpp.Send(m);
                }
                else if (msg.Subject == "gamestarted")
                {
                    int port = -1;
                    if (Int32.TryParse(msg.Body, out port))
                    {
                        Gaming.StartGame(port);
                    }
                    //RefreshLists();
                }
                break;

            case MessageType.error:
                break;

            case MessageType.chat:
                break;

            case MessageType.groupchat:
                break;

            case MessageType.headline:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }