├── README.md ├── LICENSE-MIT └── install gateway.bat /README.md: -------------------------------------------------------------------------------- 1 | Universal Battle.net Gateway Installer 2 | ============================ 3 | 4 | This script adds a new PvPGN server in the Windows registry without removing existing servers. 5 | As a server owner you can setup the script by once and then distribute it to your players. 6 | 7 | ![](http://habrastorage.org/storage2/e17/808/bf1/e17808bf1f80288d44e2928f326bcc41.png) 8 | 9 | 10 | ## Installation 11 | 12 | Setup is pretty simple - just open the BAT file with any text editor and edit several variables: 13 | ``` 14 | :: server connection 15 | set title=Your Server Name 16 | set address=127.0.0.1 17 | set timezone=1 18 | 19 | :: games to setup in the registry (true or false) 20 | set starcraft=true 21 | set warcraft3=true 22 | set diablo2=true 23 | ``` 24 | 25 | Then rename file to `install {SERVERNAME} gateway.bat`. For example, `install iccup gateway.bat` 26 | -------------------------------------------------------------------------------- /LICENSE-MIT: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012 HarpyWar (harpywar@gmail.com) 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is furnished 8 | to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /install gateway.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | :: Universal Battle.net Gateway Installer v1.0 3 | :: https://github.com/HarpyWar/battle.net-gateway-installer 4 | :: 5 | :: (c) 2012, HarpyWar (http://harpywar.com) 6 | 7 | 8 | :: -- CONFIGURATION START -- 9 | 10 | 11 | :: server connection 12 | :: 13 | set title=Your Server Name 14 | set address=localhost 15 | set timezone=1 16 | 17 | 18 | :: games to setup in the registry (true or false) 19 | :: 20 | set starcraft=true 21 | set warcraft3=true 22 | set diablo2=false 23 | 24 | 25 | :: -- CONFIGURATION END -- 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | set HKCU=HKEY_CURRENT_USER\Software 60 | 61 | set starcraft_title=Starcraft 62 | set starcraft_path=%HKCU%\Battle.net\Configuration 63 | set starcraft_key=Battle.net Gateways 64 | 65 | set warcraft3_title=Warcraft 3 66 | set warcraft3_path=%HKCU%\Blizzard Entertainment\Warcraft III 67 | set warcraft3_key=%starcraft_key% 68 | 69 | set diablo2_title=Diablo 2 70 | set diablo2_path=%starcraft_path% 71 | set diablo2_key=Diablo II Battle.net Gateways 72 | set diablo2_bnetip=%HKCU%\Blizzard Entertainment\Diablo II 73 | 74 | 75 | TITLE Universal Battle.net Gateway Installer 76 | color 9f 77 | echo - - - - - - - - - - - - - - - - - - - - - 78 | echo. 79 | echo UNIVERSAL BATTLE.NET GATEWAY INSTALLER 80 | echo. 81 | echo - - - - - - - - - - - - - - - - - - - - - 82 | echo. 83 | echo. 84 | echo Title: %title% 85 | echo Address: %address% 86 | echo Timezone: %timezone% 87 | echo. 88 | 89 | if %starcraft%==true call :addserver "starcraft_path" "starcraft_key" "starcraft_title" 90 | if %warcraft3%==true call :addserver "warcraft3_path" "warcraft3_key" "warcraft3_title" 91 | if %diablo2%==true ( 92 | call :addserver "diablo2_path" "diablo2_key" "diablo2_title" 93 | call :updatebnetip "diablo2_bnetip" "diablo2_title" 94 | ) 95 | 96 | 97 | echo. 98 | echo. 99 | echo. 100 | 101 | pause 102 | goto :eof 103 | 104 | 105 | 106 | 107 | :: add server to registry in the game serverlist 108 | :addserver 109 | setlocal EnableDelayedExpansion 110 | 111 | set reg_path=!%~1! 112 | set reg_key=!%~2! 113 | set game_title=!%~3! 114 | 115 | echo. 116 | echo [%game_title%] 117 | 118 | :: -- STEP 1 -- (read parameter from registry) 119 | 120 | set /a line_count=0 121 | 122 | :: search parameter in the registry and get cmd output result with a line delimeter "*" 123 | set cmd=REG QUERY "%reg_path%" /v "%reg_key%" 124 | FOR /F "delims=" %%i IN ('%cmd%') DO if ("!out!"=="") (set out=%%i) else (set /a line_count+=1 & set out=!out!*%%i) 125 | 126 | :: if parameter found in the registry then append serverlist 127 | if %line_count% == 2 ( 128 | for /F "tokens=1,2,3 delims=*" %%a in ("%out%") do set multistr=%%b 129 | rem echo !multistr! 130 | 131 | :: get start position 132 | call :strlen start "reg_key" 133 | :: spaces 134 | set /a start+=8 135 | 136 | :: get row type (REG_MULTI_SZ or REG_BINARY) 137 | call :substr _type !start! 10 "multistr" 138 | if "!_type!"=="REG_BINARY" ( 139 | set /a start+=10 140 | ) else ( 141 | set /a start+=12 142 | ) 143 | 144 | :: spaces 145 | set /a start+=4 146 | rem echo !start! 147 | 148 | :: get all result text length 149 | call :strlen len "multistr" 150 | set /a len-=!start! 151 | rem echo !len! 152 | 153 | :: get multistring data 154 | call :substr _substr !start! !len! "multistr" 155 | set serverlist=!_substr! 156 | 157 | 158 | :: if serverslist in binary format then convert it to ascii 159 | if "!_type!"=="REG_BINARY" ( 160 | rem echo BINARY data detected! 161 | :: convert hex to string 162 | call :hex2ascii serverlist 163 | 164 | :: remove \0\0 at the end 165 | set serverlist=!serverlist:~0,-4! 166 | 167 | :: delete binary key from the registry 168 | rem set cmd=REG DELETE "%reg_path%" /v "%reg_key%" /f 169 | rem for /f "delims=" %%i in ('!cmd!') do set out=%%i 170 | ) 171 | ) else ( 172 | set serverlist=1001\000 173 | ) 174 | 175 | rem echo !serverlist! 176 | 177 | :: -- STEP 2 -- (add parameter into registry) 178 | 179 | set isfound=0 180 | :: find server in the serverlist 181 | for /f "delims=" %%i in ('echo "!serverlist!" ^| find "%address%"') do set isfound=%%i 182 | 183 | :: if server not found then add it 184 | if %isfound% equ 0 ( 185 | set serverlist=!serverlist!\0%address%\0%timezone%\0%title% 186 | 187 | :: select this server 188 | rem echo !serverlist! 189 | call :servercount count "serverlist" 190 | call :selectserver !count! "serverlist" 191 | rem echo !serverlist! 192 | 193 | set cmd=REG ADD "%reg_path%" /v "%reg_key%" /f /t REG_MULTI_SZ /d "!serverlist!" 194 | for /f "delims=" %%i in ('!cmd!') do set out=%%i 195 | rem echo !out! 196 | echo Server was added 197 | ) else ( 198 | echo Server is already exists 199 | ) 200 | 201 | endlocal 202 | exit /b 203 | 204 | 205 | :: update bnetip key (needed for diablo 2) 206 | :updatebnetip 207 | setlocal EnableDelayedExpansion 208 | 209 | set reg_path=!%~1! 210 | set reg_key=BNETIP 211 | set game_title=!%~2! 212 | 213 | set cmd=REG ADD "%reg_path%" /v "%reg_key%" /f /t REG_SZ /d "%address%" 214 | for /f "delims=" %%i in ('!cmd!') do set out=%%i 215 | rem echo %out% 216 | echo Gateway selected 217 | 218 | endlocal 219 | exit /b 220 | 221 | 222 | :: return length of string 223 | :strlen 224 | ( 225 | setlocal EnableDelayedExpansion 226 | set "s=!%~2!#" 227 | set "len=0" 228 | for %%P in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do ( 229 | if "!s:~%%P,1!" NEQ "" ( 230 | set /a "len+=%%P" 231 | set "s=!s:~%%P!" 232 | ) 233 | ) 234 | ) 235 | ( 236 | endlocal 237 | set "%~1=%len%" 238 | exit /b 239 | ) 240 | 241 | :: return text substring from start to length 242 | :substr 243 | ( 244 | setlocal EnableDelayedExpansion 245 | set _str=!%~4! 246 | set _substr=!_str:~%2,%3! 247 | ) 248 | ( 249 | endlocal 250 | set "%~1=%_substr%" 251 | exit /b 0 252 | ) 253 | 254 | :: return servers count from the serverlist 255 | :servercount 256 | ( 257 | setlocal EnableDelayedExpansion 258 | set _str=!%~2! 259 | 260 | set char=\0 261 | set count=0 262 | 263 | :loop 264 | if !_str:~0^,2! equ !char! ( 265 | set /a count+=1 266 | ) 267 | if "!_str:~1!" neq "" ( 268 | set _str=!_str:~1! 269 | goto :loop 270 | ) 271 | set /a count -= 1 272 | set /a count /= 3 273 | ) 274 | ( 275 | endlocal 276 | set "%~1=%count%" 277 | exit /b 0 278 | ) 279 | 280 | :: update current server in the serverlist header 281 | :selectserver 282 | ( 283 | setlocal EnableDelayedExpansion 284 | 285 | set servernum=%1 286 | set serverlist=!%~2! 287 | 288 | :: trim left 289 | set str=!serverlist! 290 | for /f "tokens=* delims= " %%a in ("!str!") do set str=%%a 291 | 292 | :: remove header 293 | set str=!str:~8! 294 | rem echo !str! 295 | 296 | :: add new header 297 | call :strlen len servernum 298 | :: add 0 before selected number if there is only one digit 299 | if !len! lss 2 set servernum=0!servernum! 300 | rem echo !len! 301 | 302 | set _serverlist=1001\0!servernum!!str! 303 | ) 304 | ( 305 | endlocal 306 | set "%~2=%_serverlist%" 307 | exit /b 0 308 | ) 309 | 310 | :hex2ascii 311 | set count=0 312 | set hex=!%~1! 313 | set newline=\0 314 | 315 | :_nextchar 316 | 317 | :: get 2 hex chars 318 | call :substr val !count! 2 hex 319 | 320 | if "!val!" neq "" ( 321 | rem echo. 322 | rem echo %val% 323 | 324 | if "!val!" equ "00" ( 325 | set char=%newline% 326 | ) else ( 327 | set /a decimal=0x!val! 328 | rem echo !decimal! 329 | 330 | cmd /c exit /b !decimal! 331 | set char=!=ExitCodeAscii! 332 | ) 333 | 334 | 335 | set ascii=!ascii!!char! 336 | rem echo !ascii! 337 | 338 | set /a count+=2 339 | goto :_nextchar 340 | ) 341 | 342 | rem echo !ascii! 343 | 344 | set "%~1=%ascii%" 345 | exit /b 0 346 | 347 | --------------------------------------------------------------------------------