Ticket #3143: 3143_lobby_data_v2.3.patch
File 3143_lobby_data_v2.3.patch, 13.0 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/gamesetup/gamesetup.js
676 676 { 677 677 if (g_IsController && Engine.HasXmppClient()) 678 678 { 679 let playerNames = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name);680 Engine.SendChangeStateGame( playerNames.length, playerNames.join(", "));679 let clients = formatClients(); 680 Engine.SendChangeStateGame(clients.playersLength, clients.players, clients.observers); 681 681 } 682 682 683 683 Engine.SwitchGuiPage("page_loading.xml", { … … 1926 1926 setReady(false, false); 1927 1927 } 1928 1928 1929 function formatClients() 1930 { 1931 let observerNames = []; 1932 let playerNames = []; 1933 for (let guid in g_PlayerAssignments) 1934 { 1935 if (g_PlayerAssignments[guid].player > g_GameAttributes.settings.PlayerData.length) 1936 continue; 1937 if (g_PlayerAssignments[guid].player == -1) 1938 observerNames.push(g_PlayerAssignments[guid].name); 1939 else 1940 playerNames.push({ 1941 "name": g_PlayerAssignments[guid].name, 1942 "team": g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1].Team + 1 1943 }); 1944 } 1945 return { 1946 "players": encodeURI(JSON.stringify(playerNames)), 1947 "playersLength": playerNames.length, 1948 "observers": encodeURI(JSON.stringify(observerNames)) 1949 }; 1950 } 1951 1929 1952 /** 1930 1953 * Send the relevant gamesettings to the lobbybot. 1931 1954 */ … … 1939 1962 1940 1963 let mapSize = g_GameAttributes.mapType == "random" ? Engine.GetGUIObjectByName("mapSize").list_data[selectedMapSize] : "Default"; 1941 1964 let victoryCondition = Engine.GetGUIObjectByName("victoryCondition").list[selectedVictoryCondition]; 1942 let playerNames = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name).sort();1965 let clients = formatClients(); 1943 1966 1944 1967 let stanza = { 1945 1968 "name": g_ServerName, … … 1949 1972 "mapSize": mapSize, 1950 1973 "mapType": g_GameAttributes.mapType, 1951 1974 "victoryCondition": victoryCondition, 1952 "nbp": Object.keys(g_PlayerAssignments).length || 1, 1953 "tnbp": g_GameAttributes.settings.PlayerData.length, 1954 "players": playerNames.join(", ") 1975 "nbp": clients.playersLength, 1976 "maxnbp": g_GameAttributes.settings.PlayerData.length, 1977 "players": clients.players, 1978 "observers": clients.observers 1955 1979 }; 1956 1980 1957 1981 // Only send the stanza if the relevant settings actually changed -
binaries/data/mods/public/gui/lobby/lobby.js
285 285 return true; 286 286 287 287 if (playersNumberFilter.selected != 0 && 288 game. tnbp != playersNumberFilter.list_data[playersNumberFilter.selected])288 game.maxnbp != playersNumberFilter.list_data[playersNumberFilter.selected]) 289 289 return true; 290 290 291 291 if (mapTypeFilter.selected != 0 && … … 292 292 game.mapType != mapTypeFilter.list_data[mapTypeFilter.selected]) 293 293 return true; 294 294 295 if (!showFullFilter.checked && game. tnbp <= game.nbp)295 if (!showFullFilter.checked && game.maxnbp <= game.nbp) 296 296 return true; 297 297 298 298 return false; … … 555 555 break; 556 556 case 'nPlayers': 557 557 // Compare playercount ratio 558 sortA = a.nbp * b. tnbp;559 sortB = b.nbp * a. tnbp;558 sortA = a.nbp * b.maxnbp; 559 sortB = b.nbp * a.maxnbp; 560 560 break; 561 561 case 'status': 562 562 default: … … 591 591 list_mapName.push(translateMapTitle(game.niceMapName)); 592 592 list_mapSize.push(translateMapSize(game.mapSize)); 593 593 list_mapType.push(g_MapTypes.Title[mapTypeIdx] || ""); 594 list_nPlayers.push(game.nbp + "/" + game. tnbp);594 list_nPlayers.push(game.nbp + "/" + game.maxnbp); 595 595 list.push(gameName); 596 596 list_data.push(i); 597 597 } … … 625 625 626 626 Engine.GetGUIObjectByName("sgMapName").caption = translateMapTitle(game.niceMapName); 627 627 Engine.GetGUIObjectByName("sgNbPlayers").caption = sprintf( 628 translate("Players: %(current)s/%( total)s"), {628 translate("Players: %(current)s/%(max)s"), { 629 629 "current": game.nbp, 630 " total": game.tnbp630 "max": game.maxnbp 631 631 }); 632 632 633 Engine.GetGUIObjectByName("sgPlayersNames").caption = game.players; 633 let players = JSON.parse(decodeURI(game.players)); 634 let observers = JSON.parse(decodeURI(game.observers)); 635 let teams = []; 636 for (let player of players) 637 { 638 let teamIndex = player.team; 639 if (!teams[teamIndex]) 640 teams[teamIndex] = []; 641 teams[teamIndex].push(player.name); 642 } 643 644 let playersCaption = ""; 645 for (let team in teams) 646 { 647 teams[team].sort(); 648 playersCaption += (team == 0 ? sprintf(translate("No Team: %(players)s\n"), { "players": teams[team].join(", ") }) : 649 sprintf(translate("Team %(teamnumber)s: %(players)s\n"), { "teamnumber": team, "players": teams[team].join(", ") }) 650 ); 651 } 652 if (observers.length) 653 playersCaption += sprintf(translatePlural("Observer: %(observers)s", "Observers: %(observers)s", observers.length), { "observers": observers.sort().join(", ") }); 654 655 Engine.GetGUIObjectByName("sgPlayersNames").caption = playersCaption; 634 656 Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(game.mapSize); 635 657 636 658 let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType); … … 662 684 663 685 let username = g_UserRating ? g_Username + " (" + g_UserRating + ")" : g_Username; 664 686 665 if (game.state == "init" || game.players.split(", ").indexOf(username) > -1) 687 if (game.state == "init" || 688 JSON.parse(decodeURI(game.players)).some(player => player.name == username) || 689 JSON.parse(decodeURI(game.observers)).indexOf(username) > -1) 666 690 joinSelectedGame(); 667 691 else 668 692 messageBox( -
binaries/data/mods/public/gui/session/messages.js
536 536 // Update lobby gamestatus 537 537 if (g_IsController && Engine.HasXmppClient()) 538 538 { 539 let players = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name); 540 Engine.SendChangeStateGame(Object.keys(g_PlayerAssignments).length, players.join(", ")); 539 let observerNames = []; 540 let playerNames = []; 541 let playerData = getPlayerData(); 542 for (let guid in g_PlayerAssignments) 543 { 544 if (g_PlayerAssignments[guid].player == -1) 545 observerNames.push(g_PlayerAssignments[guid].name); 546 else 547 playerNames.push({ 548 "name": g_PlayerAssignments[guid].name, 549 "team": playerData[g_PlayerAssignments[guid].player].team + 1 550 }); 551 } 552 Engine.SendChangeStateGame(playerNames.length, encodeURI(JSON.stringify(playerNames)), encodeURI(JSON.stringify(observerNames))); 541 553 } 542 554 } 543 555 -
source/lobby/IXmppClient.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 38 38 virtual void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data) = 0; 39 39 virtual void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data) = 0; 40 40 virtual void SendIqUnregisterGame() = 0; 41 virtual void SendIqChangeStateGame(const std::string& nbp, const std::string& players ) = 0;41 virtual void SendIqChangeStateGame(const std::string& nbp, const std::string& players, const std::string& observers) = 0; 42 42 virtual void SetNick(const std::string& nick) = 0; 43 43 virtual void GetNick(std::string& nick) = 0; 44 44 virtual void kick(const std::string& nick, const std::string& reason) = 0; -
source/lobby/scripting/JSInterface_Lobby.cpp
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 46 46 scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendRegisterGame>("SendRegisterGame"); 47 47 scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendGameReport>("SendGameReport"); 48 48 scriptInterface.RegisterFunction<void, &JSI_Lobby::SendUnregisterGame>("SendUnregisterGame"); 49 scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame");49 scriptInterface.RegisterFunction<void, std::wstring, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame"); 50 50 scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetPlayerList>("GetPlayerList"); 51 51 scriptInterface.RegisterFunction<void, &JSI_Lobby::LobbyClearPresenceUpdates>("LobbyClearPresenceUpdates"); 52 52 scriptInterface.RegisterFunction<int, &JSI_Lobby::LobbyGetMucMessageCount>("LobbyGetMucMessageCount"); … … 171 171 g_XmppClient->SendIqUnregisterGame(); 172 172 } 173 173 174 void JSI_Lobby::SendChangeStateGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nbp, const std::wstring& players )174 void JSI_Lobby::SendChangeStateGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nbp, const std::wstring& players, const std::wstring& observers) 175 175 { 176 176 if (!g_XmppClient) 177 177 return; 178 g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players) );178 g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players), utf8_from_wstring(observers)); 179 179 } 180 180 181 181 JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate) -
source/lobby/scripting/JSInterface_Lobby.h
1 /* Copyright (C) 201 4Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 43 43 void SendGameReport(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data); 44 44 void SendRegisterGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data); 45 45 void SendUnregisterGame(ScriptInterface::CxPrivate* pCxPrivate); 46 void SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nbp, const std::wstring& players );46 void SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nbp, const std::wstring& players, const std::wstring& observers); 47 47 JS::Value GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate); 48 48 void LobbyClearPresenceUpdates(ScriptInterface::CxPrivate* pCxPrivate); 49 49 int LobbyGetMucMessageCount(ScriptInterface::CxPrivate* pCxPrivate); -
source/lobby/XmppClient.cpp
408 408 * decides which - but we need to update the current players that are 409 409 * in-game so the server can make the calculation. 410 410 */ 411 void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players )411 void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players, const std::string& observers) 412 412 { 413 413 glooxwrapper::JID xpartamuppJid(m_xpartamuppId); 414 414 … … 418 418 glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game"); 419 419 game->addAttribute("nbp", nbp); 420 420 game->addAttribute("players", players); 421 game->addAttribute("observers", observers); 421 422 g->m_GameList.emplace_back(game); 422 423 423 424 glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid); … … 502 503 JSAutoRequest rq(cx); 503 504 504 505 scriptInterface.Eval("([])", ret); 505 const char* stats[] = { "name", "ip", "port", "state", "nbp", " tnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" };506 const char* stats[] = { "name", "ip", "port", "state", "nbp", "maxnbp", "players", "observers", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" }; 506 507 for(const glooxwrapper::Tag* const& t : m_GameList) 507 508 { 508 509 JS::RootedValue game(cx); -
source/lobby/XmppClient.h
68 68 void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data); 69 69 void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data); 70 70 void SendIqUnregisterGame(); 71 void SendIqChangeStateGame(const std::string& nbp, const std::string& players );71 void SendIqChangeStateGame(const std::string& nbp, const std::string& players, const std::string& observers); 72 72 void SetNick(const std::string& nick); 73 73 void GetNick(std::string& nick); 74 74 void kick(const std::string& nick, const std::string& reason);