bioslobbyservice.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. // ip, name, connection port, queryPort
  2. typedef Param4<string, string, int, int> CachedServerInfo;
  3. // Script File
  4. enum ESortType
  5. {
  6. HOST,
  7. TIME,
  8. POPULATION,
  9. SLOTS,
  10. PING
  11. FAVORITE,
  12. PASSWORDED,
  13. QUEUE,
  14. MAP
  15. };
  16. enum ESortOrder
  17. {
  18. ASCENDING,
  19. DESCENDING,
  20. };
  21. class ServerBrowserHelperFunctions
  22. {
  23. static ref ServerBrowserHelperFunctions s_ServerBrowserHelperFunctions;
  24. protected static const string CHERNARUS_MAP_IMAGE = ""; // placeholder image path
  25. protected static const string LIVONIA_MAP_IMAGE = ""; // placeholder image path
  26. protected static const string SAKHAL_MAP_IMAGE = ""; // placeholder image path
  27. protected static const string LOWERCASE_ALPHABET = "abcdefghijklmnopqrstuvwxyz"; // used for temporary hotfix
  28. static ref map<string, string> INTERNAL_MAP_NAMES = new map<string, string>;
  29. void ServerBrowserHelperFunctions()
  30. {
  31. INTERNAL_MAP_NAMES.Insert("chernarusplus", "Chernarus");
  32. INTERNAL_MAP_NAMES.Insert("enoch", "Livonia");
  33. INTERNAL_MAP_NAMES.Insert("sakhal", "Sakhal");
  34. }
  35. // Use this function to add maps to the server browser map filter options
  36. static void AddMapInfo(string mapName, string mapDisplayName)
  37. {
  38. string mdn;
  39. if (!INTERNAL_MAP_NAMES.Find(mapName, mdn))
  40. INTERNAL_MAP_NAMES.Insert(mapName, mapDisplayName);
  41. }
  42. // Returns internal map name (mission world name) depending on given map display name if it can be fetched from CfgWorlds config.
  43. static string GetInternalMapName(string mapName)
  44. {
  45. string internalMapName;
  46. foreach (string mn, string mdp: INTERNAL_MAP_NAMES)
  47. {
  48. if (mdp == mapName)
  49. {
  50. internalMapName = mn;
  51. break;
  52. }
  53. }
  54. return internalMapName;
  55. }
  56. // Returns map display name depending on given internal map name (mission world name).
  57. static string GetMapDisplayName(string mapName)
  58. {
  59. string displayMapName;
  60. string internalMapName = mapName;
  61. internalMapName.ToLower();
  62. foreach (string mn, string mdp: INTERNAL_MAP_NAMES)
  63. {
  64. if (mn == internalMapName)
  65. {
  66. displayMapName = mdp;
  67. break;
  68. }
  69. }
  70. if (displayMapName == "")
  71. {
  72. displayMapName = mapName;
  73. string fc = displayMapName[0];
  74. if (fc != "")
  75. {
  76. // temporary fix for VME until fixed internaly
  77. if (LOWERCASE_ALPHABET.IndexOf(fc) > -1)
  78. {
  79. fc.ToUpper();
  80. }
  81. displayMapName[0] = fc;
  82. }
  83. }
  84. return displayMapName;
  85. }
  86. // Returns map image texture path depending on given internal map name (mission world name).
  87. static string GetServerMapImagePath(string mapName)
  88. {
  89. string image;
  90. mapName.ToLower();
  91. switch (mapName)
  92. {
  93. case "enoch":
  94. {
  95. image = LIVONIA_MAP_IMAGE;
  96. break;
  97. }
  98. case "chernarusplus":
  99. {
  100. image = CHERNARUS_MAP_IMAGE;
  101. break;
  102. }
  103. case "sakhal":
  104. {
  105. image = SAKHAL_MAP_IMAGE;
  106. break;
  107. }
  108. }
  109. return image;
  110. }
  111. static ServerBrowserHelperFunctions GetInstance()
  112. {
  113. if (!s_ServerBrowserHelperFunctions)
  114. s_ServerBrowserHelperFunctions = new ServerBrowserHelperFunctions;
  115. return s_ServerBrowserHelperFunctions;
  116. }
  117. }
  118. class GetServerModListResult
  119. {
  120. string m_Id; // server id (IP:Port)
  121. array<string> m_Mods;
  122. }
  123. //! GetServersResultRow the output structure of the GetServers operation that represents one game server
  124. class GetServersResultRow
  125. {
  126. string m_Id; // PC is IP:Port
  127. int m_Priority; // PC something is working -> 667223046
  128. string m_Name; // PC is name of server
  129. string m_Description; // PC not work
  130. string m_HostIp; // PC not work
  131. int m_HostPort; // PC is works
  132. bool m_Invisible;
  133. bool m_Official;
  134. string m_MapNameToRun; // map that server is running: "enoch" for Livonia, "chernarusplus" for Chernarus, "sakhal" for Sakhal
  135. bool m_Modded; // specifies whether a PC server uses mods
  136. int m_ModeId; // identifies if third person is allowed on a CONSOLE server. On PC always 0
  137. bool m_AntiCheat;
  138. int m_RegionId; // PC not work always 0
  139. int m_MinPlayers;
  140. int m_MaxPlayers; // PC - max players
  141. int m_FreeSlots; // PC - max players
  142. int m_CurrentNumberPlayers;
  143. int m_PlayersInQueue;
  144. string m_GameVersion; // PC not work alway ""
  145. bool m_IsPasswordProtected; // PC work
  146. string m_CreatedAt;
  147. string m_UpdatedAt;
  148. bool m_MouseAndKeyboardEnabled;
  149. bool m_WhitelistEnabled;
  150. bool m_IsDLC;
  151. //Scripted
  152. bool m_IsExpanded;
  153. int m_SortName;
  154. int m_SortTime;
  155. bool m_IsSelected;
  156. //characters alive
  157. string m_CharactersAlive;
  158. //steam friends - list of names separated by comma
  159. string m_SteamFriends;
  160. int m_Ping;
  161. string m_TimeOfDay;
  162. //! disable3rdPerson servers for mode regular/hardcore
  163. int m_Disable3rdPerson; //1 for disabled, ie. hardcore
  164. //! time multiplier of environment
  165. float m_EnvironmentTimeMul;
  166. float m_EnvironmentNightTimeMul;
  167. bool m_AllowedFilePatching;
  168. string m_ShardId;
  169. int m_SteamQueryPort;
  170. bool m_Favorite;
  171. string GetIpPort()
  172. {
  173. #ifdef PLATFORM_WINDOWS
  174. return m_Id;
  175. #else
  176. return GetIP() + ":" + m_HostPort;
  177. #endif
  178. }
  179. string GetIP()
  180. {
  181. #ifdef PLATFORM_WINDOWS
  182. // Hack - In new Serverborwser on PC has bad m_HostIp but ID contains correct IP
  183. array<string> parts = new array<string>;
  184. m_Id.Split(":", parts);
  185. return parts[0];
  186. #else
  187. return m_HostIp;
  188. #endif
  189. }
  190. bool IsSelected()
  191. {
  192. return m_IsSelected;
  193. }
  194. string GetValueStr(ESortType sort_type)
  195. {
  196. switch( sort_type )
  197. {
  198. case ESortType.HOST:
  199. {
  200. return m_Name;
  201. }
  202. case ESortType.MAP:
  203. {
  204. // m_MapNameToRun should never be a empty string but just in case we check before getting the map display name
  205. if (m_MapNameToRun != "")
  206. return ServerBrowserHelperFunctions.GetMapDisplayName(m_MapNameToRun);
  207. }
  208. }
  209. return "";
  210. }
  211. int GetValueInt(ESortType sort_type)
  212. {
  213. switch( sort_type )
  214. {
  215. case ESortType.TIME:
  216. {
  217. return m_SortTime;
  218. }
  219. case ESortType.POPULATION:
  220. {
  221. return m_CurrentNumberPlayers;
  222. }
  223. case ESortType.SLOTS:
  224. {
  225. return m_MaxPlayers;
  226. }
  227. case ESortType.PING:
  228. {
  229. return m_Ping;
  230. }
  231. case ESortType.QUEUE:
  232. {
  233. return m_PlayersInQueue;
  234. }
  235. }
  236. return 0;
  237. }
  238. // Returns 0 if values are equal,
  239. // a positive number if this entry is "greater than" other,
  240. // and a negative number if this entry is "less than" other
  241. int CompareTo(GetServersResultRow other, ESortType sortType)
  242. {
  243. // string comparison
  244. if (sortType == ESortType.HOST || sortType == ESortType.MAP)
  245. {
  246. string val1 = this.GetValueStr(sortType);
  247. string val2 = other.GetValueStr(sortType);
  248. if (val1 == val2)
  249. return 0;
  250. if (val1 < val2)
  251. return 1;
  252. return -1;
  253. }
  254. // int comparison
  255. int comparisonResult = other.GetValueInt(sortType) - this.GetValueInt(sortType);
  256. if (comparisonResult == 0)
  257. {
  258. // if sorting by POPULATION, break ties using QUEUE size
  259. if (sortType == ESortType.POPULATION)
  260. {
  261. comparisonResult = this.CompareTo(other, ESortType.QUEUE);
  262. }
  263. }
  264. return comparisonResult;
  265. }
  266. };
  267. typedef array<ref GetServersResultRow> GetServersResultRowArray;
  268. class GetFirstServerWithEmptySlotResult
  269. {
  270. GetServersResult m_Result;
  271. };
  272. //! GetServersInput the input structure of the GetServers operation
  273. class GetFirstServerWithEmptySlotInput
  274. {
  275. bool m_Official;
  276. string m_GameVersion;
  277. int m_RegionId;
  278. bool m_UseOfficial;
  279. bool m_UseGameVersion;
  280. bool m_UseRegionId;
  281. void SetOfficial( bool Official )
  282. {
  283. m_Official = Official;
  284. m_UseOfficial = true;
  285. }
  286. void SetGameVersion( string GameVersion )
  287. {
  288. m_GameVersion = GameVersion;
  289. m_UseGameVersion = true;
  290. }
  291. void SetRegionId( int RegionId )
  292. {
  293. m_RegionId = RegionId;
  294. m_UseRegionId = true;
  295. }
  296. };
  297. //! GetServersResult the output structure of the GetServers operation
  298. class GetServersResult
  299. {
  300. int m_Page;
  301. int m_Pages;
  302. ref GetServersResultRowArray m_Results;
  303. int m_NumServers;
  304. };
  305. //! GetServersInput the input structure of the GetServers operation
  306. class GetServersInput
  307. {
  308. bool m_AntiCheat;
  309. int m_RowsPerPage;
  310. string m_SortBy; //na of property
  311. ESortOrder m_SortOrder;
  312. string m_Name;
  313. string m_GameType;
  314. int m_Platform; // 1 - PC, 2 - xbox, 3 - PSN
  315. int m_ModeId; // identifies if third person is allowed on a CONSOLE server. On PC always 0
  316. int m_Page;
  317. string m_GameVersion;
  318. bool m_Official;
  319. bool m_Joinable;
  320. string m_MapNameToRun;
  321. bool m_IsModded;
  322. int m_MinPlayers; // minimum 1
  323. int m_MaxPlayers; // maximum 99
  324. bool m_IsPasswordProtected;
  325. int m_RegionId; // 1 - Americas, 2 - Europe, 3 - Asia
  326. int m_Priority;
  327. int m_FreeSlotsMin;
  328. int m_FreeSlotsMax;
  329. string m_HostIp;
  330. int m_HostPort;
  331. string m_FavoriteServers;
  332. bool m_MouseAndKeyboardEnabled;
  333. bool m_WhitelistEnabled;
  334. bool m_IsDLC;
  335. bool m_UseAntiCheat;
  336. bool m_UseName;
  337. bool m_UseGameType;
  338. bool m_UseModeId;
  339. bool m_UseGameVersion;
  340. bool m_UseOfficial;
  341. bool m_UseJoinable;
  342. bool m_UseMapNameToRun;
  343. bool m_UseIsModded;
  344. bool m_UseMinPlayers;
  345. bool m_UseMaxPlayers;
  346. bool m_UseIsPasswordProtected;
  347. bool m_UseRegionId;
  348. bool m_UsePriority;
  349. bool m_UseFreeSlotsMin;
  350. bool m_UseFreeSlotsMax;
  351. bool m_UseHostIp;
  352. bool m_UseHostPort;
  353. bool m_UseHostIps;
  354. bool m_UseMouseAndKeyboardEnabled;
  355. bool m_UseWhitelistEnabled;
  356. bool m_UseIsDLC;
  357. void SetAntiCheatFilter( bool anti_cheat )
  358. {
  359. m_AntiCheat = anti_cheat;
  360. m_UseAntiCheat = true;
  361. }
  362. void SetNameFilter( string name )
  363. {
  364. m_Name = name;
  365. m_UseName = true;
  366. }
  367. void SetGameTypeFilter( string game_type )
  368. {
  369. m_GameType = game_type;
  370. m_UseGameType = true;
  371. }
  372. void SetModeIdFilter( int mode_id )
  373. {
  374. m_ModeId = mode_id;
  375. m_UseModeId = true;
  376. }
  377. void SetGameVersionFilter( string game_version )
  378. {
  379. m_GameVersion = game_version;
  380. m_UseGameVersion = true;
  381. }
  382. void SetOfficialFilter( bool official )
  383. {
  384. m_Official = official;
  385. m_UseOfficial = true;
  386. }
  387. void SetJoinableFilter( bool joinable )
  388. {
  389. m_Joinable = joinable;
  390. m_UseJoinable = true;
  391. }
  392. void SetMapNameToRun( string mapNameToRun )
  393. {
  394. m_MapNameToRun = mapNameToRun;
  395. m_UseMapNameToRun = true;
  396. }
  397. void SetIsModdedFilter( bool is_modded )
  398. {
  399. m_IsModded = is_modded;
  400. m_UseIsModded = true;
  401. }
  402. void SetMinPlayersFilter( int min_players )
  403. {
  404. m_MinPlayers = min_players;
  405. m_UseMinPlayers = true;
  406. }
  407. void SetMaxPlayersFilter( int max_players )
  408. {
  409. m_MaxPlayers = max_players;
  410. m_UseMaxPlayers = true;
  411. }
  412. void SetIsPasswordProtectedFilter( bool password_protected )
  413. {
  414. m_IsPasswordProtected = password_protected;
  415. m_UseIsPasswordProtected = true;
  416. }
  417. void SetRegionIdFilter( int region )
  418. {
  419. m_RegionId = region;
  420. m_UseRegionId = true;
  421. }
  422. void SetPriorityFilter( int priority )
  423. {
  424. m_Priority = priority;
  425. m_UsePriority = true;
  426. }
  427. void SetFreeSlotsMin( int freeSlotsMin )
  428. {
  429. m_FreeSlotsMin = freeSlotsMin;
  430. m_UseFreeSlotsMin = true;
  431. }
  432. void SetFreeSlotsMax( int freeSlotsMax )
  433. {
  434. m_FreeSlotsMax = freeSlotsMax;
  435. m_UseFreeSlotsMax = true;
  436. }
  437. void SetHostIp( string hostIp )
  438. {
  439. m_HostIp = hostIp;
  440. m_UseHostIp = true;
  441. }
  442. void SetHostPort( int hostPort )
  443. {
  444. m_HostPort = hostPort;
  445. m_UseHostPort = true;
  446. }
  447. void SetMouseAndKeyboardEnabled(bool enabledMouseAndKeyboard)
  448. {
  449. m_MouseAndKeyboardEnabled = enabledMouseAndKeyboard;
  450. m_UseMouseAndKeyboardEnabled = true;
  451. }
  452. void SetFavorited( bool show )
  453. {
  454. m_SortBy += "F";
  455. AddShow( show );
  456. }
  457. void SetFriendsPlaying( bool show )
  458. {
  459. m_SortBy += "P";
  460. AddShow( show );
  461. }
  462. void SetPreviouslyPlayed( bool show )
  463. {
  464. m_SortBy += "R";
  465. AddShow( show );
  466. }
  467. void SetProperVersionMatch( bool show )
  468. {
  469. m_SortBy += "V";
  470. AddShow( show );
  471. }
  472. void SetFullServer( bool show )
  473. {
  474. m_SortBy += "S";
  475. AddShow( show );
  476. }
  477. void SetThirdPerson( bool show )
  478. {
  479. m_SortBy += "3";
  480. AddShow( show );
  481. }
  482. void SetPublic( bool show )
  483. {
  484. m_SortBy += "L";
  485. AddShow( show );
  486. }
  487. void SetAcceleratedTime( bool show )
  488. {
  489. m_SortBy += "A";
  490. AddShow( show );
  491. }
  492. void SetAllowedFilePatching( bool show )
  493. {
  494. m_SortBy += "7";
  495. AddShow( show );
  496. }
  497. void SetLAN()
  498. {
  499. m_SortBy += "N";
  500. }
  501. void SetPingFilter( int pingMaxValue )
  502. {
  503. m_SortBy += "M" + pingMaxValue + ";";
  504. }
  505. void SetBattleyeProtection(bool show)
  506. {
  507. m_SortBy += "B";
  508. AddShow(show);
  509. }
  510. void SetPassworded(bool show)
  511. {
  512. m_SortBy += "C";
  513. AddShow(show);
  514. }
  515. void AddShow( bool show )
  516. {
  517. if( show )
  518. m_SortBy += "+";
  519. else
  520. m_SortBy += "-";
  521. }
  522. void AddFavourite(string ip, int port)
  523. {
  524. m_FavoriteServers += ip + ";" + port + ";";
  525. }
  526. void SetWhitelistEnabled(bool whitelistEnabled)
  527. {
  528. m_WhitelistEnabled = whitelistEnabled;
  529. m_UseWhitelistEnabled = true;
  530. m_SortBy += "W";
  531. AddShow(whitelistEnabled);
  532. }
  533. void SetIsDLC(bool isDLC)
  534. {
  535. m_IsDLC = isDLC;
  536. m_UseIsDLC = true;
  537. m_SortBy += "D";
  538. AddShow(isDLC);
  539. }
  540. };
  541. class BiosLobbyService
  542. {
  543. //! Query game servers
  544. /*!
  545. The async result is returned in the OnDoneAsync callback.
  546. Expected errors:
  547. BAD_PARAMETER - if atleast one of the permissions is not supported on the current platform,
  548. or atleast one of the input arrays is NULL.
  549. @param inputValues input structure
  550. */
  551. proto native EBiosError GetServers(GetServersInput inputValues);
  552. //! First 1st free server
  553. /*!
  554. The async result is returned in the OnGetFirstServerWithEmptySlot callback.
  555. */
  556. proto native EBiosError GetFirstServerWithEmptySlot(GetFirstServerWithEmptySlotInput inputValues);
  557. proto native void AddServerFavorite(string ipAddress, int port, int steamQueryPort);
  558. proto native void RemoveServerFavorite(string ipAddress, int port, int steamQueryPort);
  559. proto native void GetFavoriteServers(TStringArray favServers);
  560. //! Get cached info about favorited servers (ONLY ON WINDOWS)
  561. /*!
  562. @param favServersInfoCache gets populated with data with format: key = Query End Point, value.param1 = Server Name, value.param2 = Connection Port
  563. */
  564. proto native void GetCachedFavoriteServerInfo(array<ref CachedServerInfo> favServersInfoCache);
  565. //! Async function to retrieve info about mods for specific server (only for PC)
  566. //! @param serverId have to be an id returned by callbacks issued by last call to GetServers
  567. //! if GetServers is used another time the id's must be upated
  568. proto native EBiosError GetServerModList(string serverId);
  569. //! Async callback for GetServers
  570. /*!
  571. @param result_list result object
  572. @param error error indicating success or fail of the async operation.
  573. @param response for debugging - this is the data returned by the server; or an empty string ;)
  574. */
  575. void OnDoneAsync(GetServersResult result_list, EBiosError error, string response)
  576. {
  577. /*
  578. if (result_list.m_Results != null && result_list.m_Results.Count() > 0)
  579. Print(result_list.m_Results[0].m_TimeOfDay);
  580. */
  581. OnlineServices.OnLoadServersAsync( result_list, error, response );
  582. }
  583. void OnGetFirstServerWithEmptySlot(GetFirstServerWithEmptySlotResult result_list, EBiosError error)
  584. {
  585. OnlineServices.OnAutoConnectToEmptyServer( result_list, error );
  586. }
  587. //! Async callback for GetServerModList
  588. void OnServerModList(GetServerModListResult result_list, EBiosError error)
  589. {
  590. OnlineServices.OnGetServerModList( result_list, error );
  591. }
  592. };