home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming All in One / 3D Game Programming All in One Disc.iso / 3D2E / demo / client / scripts / joinServerGui.cs < prev    next >
Encoding:
Text File  |  2005-11-23  |  4.4 KB  |  146 lines

  1. //-----------------------------------------------------------------------------
  2. // Torque Game Engine 
  3. // Copyright (C) GarageGames.com, Inc.
  4. //-----------------------------------------------------------------------------
  5.  
  6. //----------------------------------------
  7. function JoinServerGui::onWake()
  8. {
  9.    // Double check the status. Tried setting this the control
  10.    // inactive to start with, but that didn't seem to work.
  11.    //JS_joinServer.setActive(JS_serverList.rowCount() > 0);
  12.    
  13.    
  14.    // Override the next page command...
  15.    OverlayNextPage.setVisible(true);
  16.    OverlayNextPage.command = "JoinServerGui.join();";
  17.    
  18.    // Set our query and mission types to the demo game type
  19.    $Client::GameTypeQuery = $Client::GameType;
  20.    $Client::MissionTypeQuery = "any";
  21. }
  22.  
  23. //----------------------------------------
  24. function JoinServerGui::query(%this)
  25. {
  26.    queryMasterServer(
  27.       0,          // Query flags
  28.       $Client::GameTypeQuery,       // gameTypes
  29.       $Client::MissionTypeQuery,    // missionType
  30.       0,          // minPlayers
  31.       100,        // maxPlayers
  32.       0,          // maxBots
  33.       2,          // regionMask
  34.       0,          // maxPing
  35.       100,        // minCPU
  36.       0           // filterFlags
  37.       );
  38. }
  39.  
  40. //----------------------------------------
  41. function JoinServerGui::queryLan(%this)
  42. {
  43.    queryLANServers(
  44.       28000,      // lanPort for local queries
  45.       0,          // Query flags
  46.       $Client::GameTypeQuery,       // gameTypes
  47.       $Client::MissionTypeQuery,    // missionType
  48.       0,          // minPlayers
  49.       100,        // maxPlayers
  50.       0,          // maxBots
  51.       2,          // regionMask
  52.       0,          // maxPing
  53.       100,        // minCPU
  54.       0           // filterFlags
  55.       );
  56. }
  57.  
  58. //----------------------------------------
  59. function JoinServerGui::cancel(%this)
  60. {
  61.    cancelServerQuery();
  62.    JS_queryStatus.setVisible(false);
  63. }
  64.  
  65.  
  66. //----------------------------------------
  67. function JoinServerGui::join(%this)
  68. {
  69.    cancelServerQuery();
  70.    %id = JS_serverList.getSelectedId();
  71.  
  72.    // The server info index is stored in the row along with the
  73.    // rest of displayed info.
  74.    %index = getField(JS_serverList.getRowTextById(%id),6);
  75.    if (setServerInfo(%index)) {
  76.       %conn = new GameConnection(ServerConnection);
  77.       %conn.setConnectArgs($pref::Player::Name);
  78.       %conn.setJoinPassword($Client::Password);
  79.       %conn.connect($ServerInfo::Address);
  80.    }
  81.    else
  82.       MessageBoxOk("No Server Selected","You need to select a server. Press either of the Query buttons to list available servers or go back to the previous page to create your own.");
  83. }
  84.  
  85. //----------------------------------------
  86. function JoinServerGui::exit(%this)
  87. {
  88.    cancelServerQuery();
  89.    Canvas.setContent(StartMissionGui);   
  90. }
  91.  
  92. //----------------------------------------
  93. function JoinServerGui::update(%this)
  94. {
  95.    // Copy the servers into the server list.
  96.    JS_queryStatus.setVisible(false);
  97.    JS_serverList.clear();
  98.    %sc = getServerCount();
  99.    for (%i = 0; %i < %sc; %i++) {
  100.       setServerInfo(%i);
  101.       JS_serverList.addRow(%i,
  102.          $ServerInfo::Name TAB
  103.          $ServerInfo::Ping TAB
  104.          $ServerInfo::PlayerCount @ "/" @ $ServerInfo::MaxPlayers TAB
  105.          %i);  // ServerInfo index stored also
  106.    }
  107.    JS_serverList.sort(0);
  108.    JS_serverList.setSelectedRow(0);
  109.    JS_serverList.scrollVisible(0);
  110.  
  111.    //JS_joinServer.setActive(JS_serverList.rowCount() > 0);
  112.  
  113. //----------------------------------------
  114. function onServerQueryStatus(%status, %msg, %value)
  115. {
  116.    // Update query status
  117.    // States: start, update, ping, query, done
  118.    // value = % (0-1) done for ping and query states
  119.    if (!JS_queryStatus.isVisible())
  120.       JS_queryStatus.setVisible(true);
  121.  
  122.    switch$ (%status) {
  123.       case "start":
  124.          //JS_joinServer.setActive(false);
  125.          JS_queryMaster.setActive(false);
  126.          JS_statusText.setText(%msg);
  127.          JS_statusBar.setValue(0);
  128.          JS_serverList.clear();
  129.  
  130.       case "ping":
  131.          JS_statusText.setText("Ping Servers");
  132.          JS_statusBar.setValue(%value);
  133.  
  134.       case "query":
  135.          JS_statusText.setText("Query Servers");
  136.          JS_statusBar.setValue(%value);
  137.  
  138.       case "done":
  139.          JS_queryMaster.setActive(true);
  140.          JS_queryStatus.setVisible(false);
  141.          JoinServerGui.update();
  142.    }
  143. }
  144.  
  145.