Exemplo n.º 1
0
        /// <summary>
        /// Create content items and add to the display
        /// </summary>
        void ChangeItems()
        {
            addItems = 0;

            // add content to display.
            IGoogleDesktopDisplayPluginHelper pluginHelper =
                (IGoogleDesktopDisplayPluginHelper)this;

            GoogleDesktopContentItemDisplayOptions options;
            GameserverContentItem curItem;
            GoogleDesktopDisplayContentItemFlags itemFlags;
            IGoogleDesktopDisplayContentItemHelper itemHelper = null;

            options = GoogleDesktopContentItemDisplayOptions.GDD_ITEM_DISPLAY_IN_SIDEBAR;

            itemFlags =
                GoogleDesktopDisplayContentItemFlags.GDD_CONTENT_ITEM_FLAG_NO_REMOVE
                | GoogleDesktopDisplayContentItemFlags.GDD_CONTENT_ITEM_FLAG_SHAREABLE;

            DateTime now = DateTime.UtcNow;

            try
            {
                RegistryKey serverKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Imagine Interactive\Gameserver Panel\Servers");

                String[] servers = serverKey.GetSubKeyNames();

                if (servers.Length == 0)
                {
                    itemFlags = GoogleDesktopDisplayContentItemFlags.GDD_CONTENT_ITEM_FLAG_LEFT_ICON |
                        GoogleDesktopDisplayContentItemFlags.GDD_CONTENT_ITEM_FLAG_NO_REMOVE
                        ;

                    curItem = new GameserverContentItem();
                    itemHelper = (IGoogleDesktopDisplayContentItemHelper)curItem;

                    Rectangle r = getDisplayRect();
                    curItem.SetRect(r.X, r.Y, r.Width, r.Height*2);
                    pluginHelper.AddContentItem(curItem, options);

                    itemHelper.snippet = "MESSAGE";
                    itemHelper.heading = lang.getValue("noServer");
                    itemHelper.tooltip = lang.getValue("noServer");
                    itemHelper.source = "";
                    itemHelper.time_created = now;
                    itemHelper.flags = itemFlags;
                    itemHelper.layout = contentLayout;
                    itemHelper.open_command = this;
                }

                for (int i=0; i<servers.Length; i++)
                {
                    try
                    {
                        RegistryKey server = serverKey.OpenSubKey(servers[i]);

                        if (server.GetValue("category").ToString() != displayGroup)
                        {
                            continue;
                        }
                        int queryPort = Int32.Parse(server.GetValue("port").ToString());
                        if (server.GetValue("queryPort") != null)
                        {
                            queryPort = Int32.Parse(server.GetValue("queryPort").ToString());
                        }
                        String[] serverData = queryServer(server.GetValue("qstat").ToString(), server.GetValue("ip").ToString(), queryPort);

                        itemFlags = GoogleDesktopDisplayContentItemFlags.GDD_CONTENT_ITEM_FLAG_LEFT_ICON |
                            GoogleDesktopDisplayContentItemFlags.GDD_CONTENT_ITEM_FLAG_NO_REMOVE
                            ;

                        curItem = new GameserverContentItem();
                        itemHelper = (IGoogleDesktopDisplayContentItemHelper)curItem;

                        Rectangle r = getDisplayRect();
                        curItem.SetRect(r.X, r.Y, r.Width, r.Height);
                        pluginHelper.AddContentItem(curItem, options);

                        itemHelper.snippet = server.GetValue("game").ToString() + "|"
                            + server.GetValue("ip").ToString() + "|"
                            + server.GetValue("port").ToString() + "|"
                            + server.GetValue("qstat").ToString() + "|"
                            + server.GetValue("queryPort").ToString();

                        // do the actual setting of properties
                        if (serverData.Length > 3)
                        {
                            itemHelper.heading = serverData[2];
                            itemHelper.tooltip = serverData[2];
                            itemHelper.source = serverData[6]+","+serverData[5]+","+serverData[4];
                            itemHelper.snippet += "|"+serverData[3];
                        }
                        else
                        {
                            itemHelper.heading = server.GetValue("name").ToString();
                            itemHelper.tooltip = server.GetValue("name").ToString();
                            itemHelper.source = "0,0,0";
                        }
                        itemHelper.time_created = now;
                        itemHelper.flags = itemFlags;
                        itemHelper.layout = contentLayout;
                        itemHelper.open_command = this;

                        Bitmap bmp;
                        loadGameIcon(server.GetValue("game").ToString(), out bmp);
                        itemHelper.image = ImageConverter.ImageToIpicture(bmp);
                        bmp.Dispose();

                        addItems++;

                        server.Close();
                    }
                    catch (Exception E)
                    {
                        Log.Error("Error Adding Item for "+servers[i]+": "+E.Message);
                    }
                }

                serverKey.Close();
            }
            catch (Exception e)
            {
                Log.Error("on ChangeItems: "+e.Message);
            }

            // Replace & with && so that the next character won't be underlined _
            //if (itemHelper != null)
            //    itemHelper.heading = itemHelper.heading.Replace("&", "&&");

            // if we are in minimized mode, update the title with latest info.
            // displaySite will be null until plugin is fully initialized.
            if (displaySite != null && displaySite.display_state ==
                GoogleDesktopDisplayTileDisplayState.GDD_TILE_DISPLAY_STATE_MINIMIZED)
            {
                UpdateTitle();
            }
        }
Exemplo n.º 2
0
        public void OnReceiveTalkMessage( System.Object talk_friend , System.String data )
        {
            Log.Debug("Received Talk Message");
            try
            {
                IGoogleDesktopTalkFriend friend = (IGoogleDesktopTalkFriend)talk_friend;
                String[] cmd = data.Split('|');
                String game = cmd[0];
                String ip = cmd[1];
                int port = Int32.Parse(cmd[2]);

                String msg = String.Format(lang.getValue("talkInvite")+"\n",
                                                friend.name, game, ip, port);
                Log.Debug("Received Invitation for "+game+" on "+ip+":"+port+" from "+friend.name);
                RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Imagine Interactive\Gameserver Panel\Games\"+game);
                if (key == null)
                {
                    msg += String.Format( lang.getValue("talkUnknownGame"), pluginName);
                    MessageBox.Show(msg, pluginName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (key.GetValue("isInstalled").ToString() == "0")
                {
                    findGames();
                    if (key.GetValue("isInstalled").ToString() == "0")
                    {
                        msg += lang.getValue("talkGameNotInstalled");
                        MessageBox.Show(msg, pluginName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                msg += lang.getValue("talkConnect");
                key.Close();

                Log.Debug("Displaying Notification");
                GameserverContentItem item = new GameserverContentItem();
                IGoogleDesktopDisplayContentItemHelper itemHelper = (IGoogleDesktopDisplayContentItemHelper)item;
                GoogleDesktopDisplayContentItemLayout contentLayout =
                    GoogleDesktopDisplayContentItemLayout.GDD_CONTENT_ITEM_LAYOUT_NOWRAP_ITEMS;
                GoogleDesktopDisplayContentItemFlags itemFlags =
                    GoogleDesktopDisplayContentItemFlags.GDD_CONTENT_ITEM_FLAG_NONE;
                itemHelper.heading = msg;
                itemHelper.tooltip = msg;
                itemHelper.source = "0,0,0";
                itemHelper.snippet = data;
                itemHelper.flags = itemFlags;
                itemHelper.open_command = this;
                itemHelper.layout = contentLayout;

                GoogleDesktopDisplayUINotificationClass notify = new GoogleDesktopDisplayLib.GoogleDesktopDisplayUINotificationClass();
                notify.enabled = true;
                notify.AddNotification(controlGuid, item);
            }
            catch (Exception E)
            {
                Log.Error("onReceiveTalkMessage: "+E.Message);
            }
            Log.Debug("Executed Talk Message");
        }