Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Ace of Spades Server Selector (Updated June 1, 2013)


  • Please log in to reply
71 replies to this topic
Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
Thanks nimda and infogulch!

I've added the option of specifying your own path for the Ace of Spades executable. It uses "Transform, Deref", and so has support for variables inline. Also changed the parsing of addresses slightly so ports are supported and displayed.

Other changes include an error message when no connection is available, removal of the useless "Index" column, and style changes.

Fixed. Apparently as of 0.75, the aos:// link includes the port. I adjusted for it, and added port column. I also fixed the insane one-space indentation.


I usually have a tendency to keep the indentation style of existing files, and so up to now I haven't converted the indentation to my current style yet. It now uses four spaces per nesting level.

gamax92
  • Members
  • 411 posts
  • Last active: Aug 06 2013 05:00 AM
  • Joined: 05 Dec 2010
Just letting you know, the new /play update broke this.

So until Uberi properly fixes this program, heres my fix
#NoEnv

;Path := """%A_ScriptDir%\client.exe"" ""%Server%""" ;use this for portable installations
Path := "%Server%" ;use this for normal installations

URL := "http://aos.mp2.dk/"

SetTitleMatchMode, RegEx

AutoJoin := 0

Gui, Font, s16 Bold, Arial
Gui, Add, Text, x10 y0 h30 vTitle Center, Server List
Gui, Font, s8 Norm
SortColumns := [0,0,0,0,0]
Gui, Add, ListView, x10 y30 vServerList gListViewEvent, Name|Players|Capacity|Ping|Server|Address|Port
Gui, Font, Bold
Gui, Add, Text, x10 w80 h20 vServerCount
Gui, Add, Button, w80 h20 vLocalServer gLocalServer, &Local Server
Gui, Add, Button, w80 h20 vRefreshList gRefreshList Default, &Refresh
Gui, +Resize +MinSize270x150

Gosub, RefreshList

Gui, Show, Center w630 h650
Return

GuiEscape:
GuiClose:
ExitApp

GuiSize:
GuiControl, Move, Title, % "w" . (A_GuiWidth - 20)
GuiControl, Move, ServerList, % "w" . (A_GuiWidth - 20) . " h" . (A_GuiHeight - 70)
GuiControl, Move, ServerCount, % "y" . (A_GuiHeight - 30)
GuiControl, Move, LocalServer, % "x" . (A_GuiWidth - 180) . " y" . (A_GuiHeight - 30)
GuiControl, Move, RefreshList, % "x" . (A_GuiWidth - 90) . " y" . (A_GuiHeight - 30)
WinSet, Redraw
Return

LocalServer:
Gui, Hide
JoinServer("aos://16777343",Path,"Local Server")
Gui, Show
Return

ListViewEvent:
If (A_GuiEvent = "ColClick")
    Gosub, SortColumns
If (A_GuiEvent != "DoubleClick")
    Return
Gosub, SelectServer
Return

SelectServer:
Row := LV_GetNext()
LV_GetText(Server,Row,5) ;retrieve the server from the fifth column of the selected row
LV_GetText(Name,Row,1) ;retrieve the server name from the first column of the selected row
Gui, Hide
JoinServer(Server,Path,Name)
Gui, Show
Return

SortColumns:
If SortColumns[A_EventInfo]
    SortColumns[A_EventInfo] := (SortColumns[A_EventInfo] & 1) + 1 ;toggle sorting types between ascending and descending
Else
    SortColumns[A_EventInfo] := (A_EventInfo = 2 || A_EventInfo = 3) ? 2 : 1 ;enable sorting for the column

For Index In SortColumns ;disable sorting on all other columns
{
    If (Index != A_EventInfo)
        SortColumns[Index] := 0
}
Return

RefreshList:
;request the server selection page
try
{
    WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
    WebRequest.Open("GET",URL) ;open request
    WebRequest.Send() ;send request
    ServerPage := WebRequest.ResponseText ;retrieve response
    WebRequest := "" ;free request
}
catch Error
{
    WebRequest := "" ;free request
    If (Error.Extra = "Send")
        MsgBox, 16, Error, Could not request server list.
    Else If (Error.Extra = "ResponseText")
        MsgBox, 16, Error, Could not retrieve server list.
    Else
        MsgBox, 16, Error, Could not obtain server list.
    ServerPage := ""
}

RegExMatch(ServerPage,"iS)<div\b[^<]*<a\b[^>]*>[^<]*?([\d\.]+)",Output), Version := (Output1 = "") ? "Unknown Version" : ("Version " . Output1) ;find the current version

;retrieve the server list
ServerPage := SubStr(ServerPage,InStr(ServerPage,"<table>") + StrLen("<table>")) ;remove everything before the server list
ServerPage := SubStr(ServerPage,InStr(ServerPage,"<tbody>") + StrLen("<tbody>")) ;remove everything before the server list
ServerPage := SubStr(ServerPage,1,InStr(ServerPage,"</tbody>") - 1) ;remove everything after the server list
StringReplace, ServerPage, ServerPage, `r,, All ;remove carriage returns
ServerPage := Trim(ServerPage,"`n") ;trim off leading and trailing newlines
ServerPage := SubStr(ServerPage,InStr(ServerPage,"</tr>") + 5) ;remove the header row
StringReplace, ServerPage, ServerPage,</tr>,|, All ;remove carriage returns

GuiControl, -Redraw, ServerList ;prevent redrawing of the ListView

LV_Delete() ;remove all listview entries

;populate the ListView
Loop, Parse, ServerPage, |
{
    Loop, Parse, A_LoopField, `n
	{
;		MsgBox, %A_Index% - %A_LoopField%
		If (A_Index = 5)
		{
			RegExMatch(A_LoopField,">(.*?)<",match)
			StringSplit, Slot, match1,/
		}
		If (A_Index = 6)
			RegExMatch(A_LoopField,">(.*?)<",Ping)
		If (A_Index = 10)
		{
			RegExMatch(A_LoopField,"href=\""(.*?)\""",Server)
			Port := SubStr(Server1,6)
			Port := SubStr(Port,Instr(Port, ":") + 1)
			RegExMatch(A_LoopField,Server1 . "\"">(.*?)</a>",Name)
		}
	}
	ServerAddress1 := SubStr(Server1,7,StrLen(Server1)-StrLen(Port)-7)
    Address := (ServerAddress1 & 0xFF) . "." . ((ServerAddress1 & 0xFF00) >> 8) . "." . ((ServerAddress1 & 0xFF0000) >> 16) . "." . ((ServerAddress1 & 0xFF000000) >> 24)
    LV_Add("",Name1,Slot1,Slot2,Ping1,Server1,Address,Port)
}

;adjust column widths to suit their headers and contents
LV_ModifyCol(1,"AutoHdr") ;server name
LV_ModifyCol(2,"AutoHdr Integer Desc") ;players
LV_ModifyCol(3,"AutoHdr Integer Desc") ;capacity
LV_ModifyCol(4,"AutoHdr Integer") ;ping
LV_ModifyCol(5,"AutoHdr") ;server
LV_ModifyCol(6,"AutoHdr") ;IP address
LV_ModifyCol(7,"AutoHdr Integer") ;port

For Index, Value In SortColumns
{
    If Value
    {
        LV_ModifyCol(Index,"Sort" . ((Value = 1) ? "" : "Desc"))
        Break
    }
}

GuiControl, +Redraw, ServerList ;allow the ListView to be redrawn

GuiControl,, ServerCount, % LV_GetCount() . " servers." ;update the server count
Gui, Show,, Ace of Spades (%Version%) Servers
Return

JoinServer(Server,Path,Name)
{
    global AutoJoin
    Transform, Path, Deref, %Path%
    Loop
    {
        ;open Ace of Spades
        Run, %Server%,, UseErrorLevel
        If ErrorLevel
        {
            MsgBox, 16, Error, Could not open server "%Server%".
            Return, 1
        }
        WinWait, Ace of Spades|ERROR ahk_class Ace of Spades|#32770,, 5

        ;check for connection errors
        WinGetClass, WindowClass
        If (WindowClass != "Ace of Spades") ;error dialogue
        {
            WinClose
            If !AutoJoin
            {
                MsgBox, 22, Error, Could not connect to "%Name%": server is full or misconfigured.`n`nSelect "Try Again" to retry the connection`, or "Continue" to automaticially join.
                IfMsgBox, Cancel
                {
                    Gosub, StopAutoJoin
                    Break
                }
                IfMsgBox, Continue
                {
                    AutoJoin := 1
                    ToolTip, Press Esc to stop automatic retrying.
                    Hotkey, Esc, StopAutoJoin, On
                }
            }
        }
        Else
        {
            Gosub, StopAutoJoin
            If ErrorLevel ;window wait operation timed out
                Return, 1
            WinSetTitle, Ace of Spades ahk_class Ace of Spades,, Ace of Spades - %Name%
            WinWaitClose
            Break
        }
    }
    Return, 0

    StopAutoJoin:
    AutoJoin := 0
    ToolTip
    Hotkey, Esc, StopAutoJoin, Off
    Return
}

#If ListViewFocused()

ListViewFocused()
{
    GuiControlGet, CurrentFocus, FocusV
    Return, CurrentFocus = "ServerList" && LV_GetNext()
}

Enter::Gosub, SelectServer

#If

EDIT:: Placed version using pyspades server page, probably less likely to break.

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
Thanks for the fix, gamax92.

I've updated the script to display map and game mode information, since that is now also available on the web page. Additionally, the IP address and port columns have been removed, since they were not useful enough to keep.

The script is now compatible with version 0.75 and its associated web pages.

nimda
  • Members
  • 4368 posts
  • Last active: Jan 15 2014 02:47 PM
  • Joined: 26 Dec 2010

The script is now compatible with version 0.75 and its associated web pages.

Woo! I was really missing the auto-join functionality :p

I see a lot of
- Consider using UnHTM or UnHTML.

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010

I see a lot of

- Consider using UnHTM or UnHTML.


I missed that somehow during testing... now updated.

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
Update:

[*:1rzns7wz]Map name now shown in title of the game window.
[*:1rzns7wz]Window sometimes does not show controls properly sized and placed - now fixed.

GeekDude
  • Members
  • 350 posts
  • Last active: Jul 01 2014 12:51 PM
  • Joined: 23 Nov 2009
The current version of this launcher has a critical bug.
When running the game, it uses %Server% instead of %Path%
Good thing it is easy to fix :)

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
You're right, thanks for catching that.

Please redownload to get the fix.

  • Guests
  • Last active:
  • Joined: --
Why isn't this moved to gaming section already?!

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
Update:

[*:23c8vl50]Connect to a server by IP address.
[*:23c8vl50]Retrieve the server list from aos.mp2.dk if the main page is unavailable or blocked. (thanks gamax92).
[*:23c8vl50]Correctly detect when the server selection pages are being blocked.

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
Update:

[*:rgydi2vi]IP address entry now remembers address last typed.
[*:rgydi2vi]Fix autojoin.

nimda
  • Members
  • 4368 posts
  • Last active: Jan 15 2014 02:47 PM
  • Joined: 26 Dec 2010

Fix autojoin.

:D :D

infogulch
  • Moderators
  • 717 posts
  • Last active: Nov 04 2013 08:05 PM
  • Joined: 27 Mar 2008
<!-- m -->http://www.ace-spade...serverlist.json<!-- m -->

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
Sounds useful, infogulch, I'll see if I can make it use this instead of the normal server list, which is probably going to get changed again pretty soon for 0.76.

Uberi
  • Moderators
  • 1118 posts
  • Last active: Apr 04 2014 01:20 AM
  • Joined: 23 Aug 2010
Update:

[*:30cnd95k]Server list is taken from ace-spades.com/serverlist.json as a second source. It is not the first source because the current version number is not present on the page.