main.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. // Load up core script base
  23. loadDir("core"); // Should be loaded at a higher level, but for now leave -- SRZ 11/29/07
  24. //-----------------------------------------------------------------------------
  25. // Package overrides to initialize the mod.
  26. package fps {
  27. function displayHelp() {
  28. Parent::displayHelp();
  29. error(
  30. "Fps Mod options:\n"@
  31. " -dedicated Start as dedicated server\n"@
  32. " -connect <address> For non-dedicated: Connect to a game at <address>\n" @
  33. " -mission <filename> For dedicated: Load the mission\n"
  34. );
  35. }
  36. function parseArgs()
  37. {
  38. // Call the parent
  39. Parent::parseArgs();
  40. // Arguments, which override everything else.
  41. for (%i = 1; %i < $Game::argc ; %i++)
  42. {
  43. %arg = $Game::argv[%i];
  44. %nextArg = $Game::argv[%i+1];
  45. %hasNextArg = $Game::argc - %i > 1;
  46. switch$ (%arg)
  47. {
  48. //--------------------
  49. case "-dedicated":
  50. $Server::Dedicated = true;
  51. enableWinConsole(true);
  52. $argUsed[%i]++;
  53. //--------------------
  54. case "-mission":
  55. $argUsed[%i]++;
  56. if (%hasNextArg) {
  57. $missionArg = %nextArg;
  58. $argUsed[%i+1]++;
  59. %i++;
  60. }
  61. else
  62. error("Error: Missing Command Line argument. Usage: -mission <filename>");
  63. //--------------------
  64. case "-connect":
  65. $argUsed[%i]++;
  66. if (%hasNextArg) {
  67. $JoinGameAddress = %nextArg;
  68. $argUsed[%i+1]++;
  69. %i++;
  70. }
  71. else
  72. error("Error: Missing Command Line argument. Usage: -connect <ip_address>");
  73. }
  74. }
  75. }
  76. function onStart()
  77. {
  78. // The core does initialization which requires some of
  79. // the preferences to loaded... so do that first.
  80. exec( "./client/defaults.cs" );
  81. exec( "./server/defaults.cs" );
  82. Parent::onStart();
  83. echo("\n--------- Initializing Directory: scripts ---------");
  84. // Load the scripts that start it all...
  85. exec("./client/init.cs");
  86. exec("./server/init.cs");
  87. // Init the physics plugin.
  88. physicsInit();
  89. // Start up the audio system.
  90. sfxStartup();
  91. // Server gets loaded for all sessions, since clients
  92. // can host in-game servers.
  93. initServer();
  94. // Start up in either client, or dedicated server mode
  95. if ($Server::Dedicated)
  96. initDedicated();
  97. else
  98. initClient();
  99. }
  100. function onExit()
  101. {
  102. // Ensure that we are disconnected and/or the server is destroyed.
  103. // This prevents crashes due to the SceneGraph being deleted before
  104. // the objects it contains.
  105. if ($Server::Dedicated)
  106. destroyServer();
  107. else
  108. disconnect();
  109. // Destroy the physics plugin.
  110. physicsDestroy();
  111. echo("Exporting client prefs");
  112. export("$pref::*", "./client/prefs.cs", False);
  113. echo("Exporting server prefs");
  114. export("$Pref::Server::*", "./server/prefs.cs", False);
  115. BanList::Export("./server/banlist.cs");
  116. Parent::onExit();
  117. }
  118. }; // package fps
  119. // Activate the game package.
  120. activatePackage(fps);