Server.cs 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. ForceRequiredAddOn("Script_Player_Persistence");
  2. exec("./Preferences.cs");
  3. registerPrefs();
  4. package StargateWandering
  5. {
  6. function GameConnection::createPlayer(%cl, %trans)
  7. {
  8. RegisterPersistenceVar("Stargate", false, "");
  9. RegisterPersistenceVar("StargatePos", false, "");
  10. RegisterPersistenceVar("StargateSpawn", false, "");
  11. if(!%cl.hasSpawnedOnce || %cl.hasSpawnedOnce && !%cl.Stargate && !%cl.StargatePos && !%cl.StargateSpawn)
  12. {
  13. %earthGate = $gateObjs["28 26 5 36 11 29"];
  14. %earthPos = %earthGate.getPosition();
  15. %earthForV = %earthGate.getForwardVector();
  16. %earthAng = mAtan(getWords(%earthForV, 0), getWords(%earthForV, 1));
  17. %cl.Stargate = %earthGate;
  18. %cl.StargatePos = %earthPos;
  19. %cl.StargateSpawn = vectorAdd(%earthPos, vectorScale(%earthForV, 4))@" 0 0 1 "@%earthAng;
  20. }
  21. if(%cl.StargateSpawn !$= "")
  22. %trans = %cl.StargateSpawn;
  23. Parent::createPlayer(%cl, %trans);
  24. if(isObject(%pl = %cl.player))
  25. %pl.StargateLoop(getSimTime());
  26. }
  27. function servercmdFind(%cl, %targ)
  28. {
  29. if(%cl.isAdmin && isObject(%targ))
  30. {
  31. %cl.Stargate = %targ.Stargate;
  32. %cl.StargatePos = %targ.StargatePos;
  33. %cl.StargateSpawn = %targ.StargateSpawn;
  34. }
  35. else if(%cl.isAdmin && isObject(%vict = findClientByName(%targ)))
  36. {
  37. %cl.Stargate = %vict.Stargate;
  38. %cl.StargatePos = %vict.StargatePos;
  39. %cl.StargateSpawn = %vict.StargateSpawn;
  40. }
  41. Parent::servercmdFind(%cl, %targ);
  42. }
  43. function servercmdFetch(%cl, %targ)
  44. {
  45. if(%cl.isAdmin && isObject(%targ))
  46. {
  47. %targ.Stargate = %cl.Stargate;
  48. %targ.StargatePos = %cl.StargatePos;
  49. %targ.StargateSpawn = %cl.StargateSpawn;
  50. }
  51. else if(%cl.isAdmin && isObject(%vict = findClientByName(%targ)))
  52. {
  53. %vict.Stargate = %cl.Stargate;
  54. %vict.StargatePos = %cl.StargatePos;
  55. %vict.StargateSpawn = %cl.StargateSpawn;
  56. }
  57. Parent::servercmdFetch(%cl, %targ);
  58. }
  59. function sendMessage(%cl, %msg) {
  60. commandToClient(%cl, 'chatMessage', %cl, '', '', "\c7"@%cl.clanPrefix@"\c3"@%cl.name@"\c7"@%cl.clanSuffix@"\c6: "@%msg, %cl.clanPrefix, %cl.name, %cl.clanSuffix, %msg);
  61. }
  62. function servercmdMessageSent(%cl, %msg)
  63. {
  64. if(isFunction("SetMode") && SetMode(%cl, %msg) == 2) return;
  65. if(!%cl.hasSpawnedOnce) %pos = "0 0 0";
  66. else %pos = %cl.getControlObject().getEyePoint();
  67. %idcHash = sha1(%cl.bl_id);
  68. %hex = "0123456789ABCDEF";
  69. for(%i=0;%i<10;%i++)
  70. {
  71. %digit = 0;
  72. for(%j=0;%j<4;%j++)
  73. %digit = (%digit << 4) | striPos(%hex, getSubStr(%idcHash, %i * 4 + %j, 1));
  74. %realIDC = %realIDC @ mFloor(%digit / 6553.6);
  75. }
  76. if(%msg $= %realIDC || (%msg !$= "" && getSubStr(%msg, 0, strLen(%msg) - 1) $= %realIDC))
  77. {
  78. if(%msg !$= %realIDC)
  79. %suffix = getSubStr(%msg, strLen(%msg) - 1, 1);
  80. %gates = StargateNetwork.getCount();
  81. for(%i=0;%i<%gates;%i++)
  82. {
  83. %gate = StargateNetwork.getObject(%i);
  84. if(isObject(%pair = %gate.linkedGate)
  85. || isObject(%pair = %gate.masterGate))
  86. {
  87. %dist = getMin(vectorDist(%pos, %gate.getPosition()),
  88. vectorDist(%pos, %pair.getPosition()));
  89. if(%dist <= 32)
  90. {
  91. initContainerRadiusSearch(%gate.getPosition(), 16, $Typemasks::fxBrickAlwaysObjectType);
  92. while(isObject(%brick = containerSearchNext()))
  93. {
  94. if(%suffix $= "")
  95. %brick.ReceivedValidIDC(%realIDC, %cl);
  96. else if(%suffix $= "D" && isObject(%gate.masterGate))
  97. %brick.ReceivedValidIDC_D(%realIDC, %cl);
  98. else if(%suffix $= "O" && isObject(%gate.linkedGate))
  99. %brick.ReceivedValidIDC_O(%realIDC, %cl);
  100. }
  101. }
  102. }
  103. }
  104. %cl.chatMessage("\c6Identification code transmitted!");
  105. return;
  106. }
  107. while((%temp = stripMLControlChars(%msg)) !$= %msg)
  108. %msg = %temp;
  109. %msg = ParseLinks(%msg);
  110. %gates = StargateNetwork.getCount();
  111. for(%i=0;%i<%gates;%i++)
  112. {
  113. %gate = StargateNetwork.getObject(%i);
  114. if(isObject(%pair = %gate.linkedGate)
  115. || isObject(%pair = %gate.masterGate))
  116. {
  117. %gateDist[%i] = getMin(vectorDist(%pos, %gate.getPosition()),
  118. vectorDist(%pos, %pair.getPosition()));
  119. }
  120. }
  121. %clients = ClientGroup.getCount();
  122. for(%i=0;%i<%clients;%i++)
  123. {
  124. %this = ClientGroup.getObject(%i);
  125. if(!%this.hasSpawnedOnce) %loc = "0 0 0";
  126. else %loc = %this.getControlObject().getEyePoint();
  127. if(vectorDist(%pos, %loc) < 256)
  128. sendMessage(%cl, %msg);
  129. else
  130. {
  131. for(%j=0;%j<%gates;%j++)
  132. {
  133. if(%gateDist[%j] $= "") continue;
  134. %sumDist = vectorDist(%loc, StargateNetwork.getObject(%j).getPosition()) + %gateDist[%j];
  135. if(%sumDist < 256) {
  136. sendMessage(%cl, %msg);
  137. break;
  138. } else {
  139. %admin = %cl.isAdmin;
  140. %superAdmin = %cl.isSuperAdmin;
  141. %host = !$Server::LAN && %cl.getBLID() == getNumKeyID();
  142. if($Pref::Server::Stargate::ChatRangeBypass && $Pref::Server::Stargate::ChatRangeBypassRank $= "1" && %admin || %superAdmin || %host) sendMessage(%cl, %msg);
  143. if($Pref::Server::Stargate::ChatRangeBypass && $Pref::Server::Stargate::ChatRangeBypassRank $= "2" && %superAdmin || %host) sendMessage(%cl, %msg);
  144. if($Pref::Server::Stargate::ChatRangeBypass && $Pref::Server::Stargate::ChatRangeBypassRank $= "3" && %host) sendMessage(%cl, %msg);
  145. }
  146. }
  147. }
  148. }
  149. echo(%cl.name@": "@%msg);
  150. }
  151. function servercmdPlantBrick(%cl)
  152. {
  153. %admin = %cl.isAdmin;
  154. %superAdmin = %cl.isSuperAdmin;
  155. %host = !$Server::LAN && %cl.getBLID() == getNumKeyID();
  156. if($Pref::Server::Stargate::BypassBorder && $Pref::Server::Stargate::BypassBorderRank $= "1" && %admin || %superAdmin || %host) return Parent::servercmdPlantBrick(%cl);
  157. if($Pref::Server::Stargate::BypassBorder && $Pref::Server::Stargate::BypassBorderRank $= "2" && %superAdmin || %host) return Parent::servercmdPlantBrick(%cl);
  158. if($Pref::Server::Stargate::BypassBorder && $Pref::Server::Stargate::BypassBorderRank $= "3" && %host) return Parent::servercmdPlantBrick(%cl);
  159. if(isObject(%pl = %cl.player) && isObject(%temp = %pl.tempbrick))
  160. {
  161. %farthest = %temp.getFarthestPoint(%cl.StargatePos);
  162. %len = vectorLen(getWords(%farthest, 0, 1));
  163. if(%len > 256)
  164. {
  165. messageClient(%cl,'MsgPlantError_TooFar');
  166. return;
  167. }
  168. }
  169. Parent::servercmdPlantBrick(%cl);
  170. }
  171. };
  172. activatePackage("StargateWandering");
  173. function ParseLinks(%msg)
  174. {
  175. %words = getWordCount(%msg);
  176. for(%i=0;%i<%words;%i++)
  177. {
  178. %word = getWord(%msg, %i);
  179. if(getSubStr(%word, 0, 7) $= "http://")
  180. %msg = setWord(%msg, %i, "<a:"@(%word=strReplace(%word, "http://", ""))@">"@%word@"</a>");
  181. else if(getSubStr(%word, 0, 8) $= "https://")
  182. %msg = setWord(%msg, %i, "<a:"@(%word=strReplace(%word, "https://", ""))@">"@%word@"</a>");
  183. else if(getSubStr(%word, 0, 6) $= "ftp://")
  184. %msg = setWord(%msg, %i, "<a:"@(%word=strReplace(%word, "ftp://", ""))@">"@%word@"</a>");
  185. }
  186. return trim(%msg);
  187. }
  188. function Player::StargateLoop(%pl, %last)
  189. {
  190. cancel(%pl.StargateLoop);
  191. %pl.StargateLoop = %pl.schedule(50, "StargateLoop");
  192. if(isObject(%cl = %pl.client))
  193. {
  194. %admin = %cl.isAdmin;
  195. %superAdmin = %cl.isSuperAdmin;
  196. %host = !$Server::LAN && %cl.getBLID() == getNumKeyID();
  197. if($Pref::Server::Stargate::BypassBorder && $Pref::Server::Stargate::BypassBorderRank $= "1" && %admin || %superAdmin || %host) return;
  198. if($Pref::Server::Stargate::BypassBorder && $Pref::Server::Stargate::BypassBorderRank $= "2" && %superAdmin || %host) return;
  199. if($Pref::Server::Stargate::BypassBorder && $Pref::Server::Stargate::BypassBorderRank $= "3" && %host) return;
  200. %diff = vectorSub(%pl.getHackPosition(), %cl.StargatePos);
  201. %len = vectorLen(getWords(%diff, 0, 1));
  202. if(%len >= 256)
  203. {
  204. %out = vectorNormalize(getWords(%diff, 0, 1));
  205. %pos = vectorAdd(%cl.StargatePos, vectorScale(%out, 256));
  206. %pl.setTransform(getWords(%pos, 0, 1) SPC getWords(%pl.getTransform(), 2, 6));
  207. %oVel = vectorScale(%out, -vectorDot(%pl.getVelocity(), %out));
  208. %pl.addVelocity(%oVel);
  209. }
  210. }
  211. }
  212. function servercmdWhatsMyIDC(%cl)
  213. {
  214. %idcHash = sha1(%cl.bl_id);
  215. %hex = "0123456789ABCDEF";
  216. for(%i=0;%i<10;%i++)
  217. {
  218. %digit = 0;
  219. for(%j=0;%j<4;%j++)
  220. %digit = (%digit << 4) | striPos(%hex, getSubStr(%idcHash, %i * 4 + %j, 1));
  221. %realIDC = %realIDC @ mFloor(%digit / 6553.6);
  222. }
  223. %cl.chatMessage("\c6Your IDC is \c4"@%realIDC@"\c6.");
  224. }
  225. function planetCmd(%cl) {
  226. %gateObj = %cl.Stargate;
  227. if (%gateObj $= null || %gateObj $= "")
  228. return %cl.chatMessage("\c0Your planet has not been located. Please travel to a different one to access the Planetary Index.");
  229. %worldName = %gateObj.worldName $= "" || %gateObj.worldName $= null ? "a Hidden System" : %gateObj.worldName;
  230. %address = %gateObj.address;
  231. %poo = %gateObj.pointOfOrigin;
  232. %cl.chatMessage("\c6You are on \c3"@%worldName@"\c6, with the address \c4"@%address@"\c6 and the point of origin as glyph \c1"@%poo@"\c6.");
  233. }
  234. function servercmdWhatsMyPlanet(%cl)
  235. {
  236. %admin = %cl.isAdmin;
  237. %superAdmin = %cl.isSuperAdmin;
  238. %host = !$Server::LAN && %cl.getBLID() == getNumKeyID();
  239. if($Pref::Server::Stargate::WhatsMyPlanetCmd && $Pref::Server::Stargate::WhatsMyPlanetCmdRank $= 1 && %admin || %superAdmin || %host) return planetCmd(%cl);
  240. if($Pref::Server::Stargate::WhatsMyPlanetCmd && $Pref::Server::Stargate::WhatsMyPlanetCmdRank $= 2 && %superAdmin || %host) return planetCmd(%cl);
  241. if($Pref::Server::Stargate::WhatsMyPlanetCmd && $Pref::Server::Stargate::WhatsMyPlanetCmdRank $= 3 && %host) return planetCmd(%cl);
  242. }
  243. exec("./Bricks/_Init.cs");
  244. exec("./Libraries/_Init.cs");
  245. exec("./Sounds/_Init.cs");
  246. exec("./BotMALP.cs");
  247. exec("./DHD.cs");
  248. exec("./Environ.cs");
  249. exec("./Events.cs");
  250. exec("./Functions.cs");
  251. exec("./MALP_AI.cs");
  252. exec("./Painting.cs");
  253. exec("./Stargate.cs");
  254. exec("./Vehicles.cs");
  255. function getUnitVector()
  256. {
  257. %elev = mAsin(getRandom() * 2 - 1);
  258. %azim = (getRandom() * 2 - 1) * $PI;
  259. %z = mSin(%elev); %l = mCos(%elev);
  260. %x = mSin(%azim) * %l;
  261. %y = mCos(%azim) * %l;
  262. return %x SPC %y SPC %z;
  263. }
  264. //Stargate outermost diameter: 8.88
  265. //Stargate innermost diameter: 7.20
  266. //Tollan gate outermost diameter: 8.50