LLUDPServerCommands.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Text;
  30. using NDesk.Options;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Console;
  33. using OpenSim.Region.Framework.Scenes;
  34. namespace OpenSim.Region.ClientStack.LindenUDP
  35. {
  36. public class LLUDPServerCommands
  37. {
  38. private ICommandConsole m_console;
  39. private LLUDPServer m_udpServer;
  40. public LLUDPServerCommands(ICommandConsole console, LLUDPServer udpServer)
  41. {
  42. m_console = console;
  43. m_udpServer = udpServer;
  44. }
  45. public void Register()
  46. {
  47. m_console.Commands.AddCommand(
  48. "Comms", false, "show server throttles",
  49. "show server throttles",
  50. "Show information about server throttles",
  51. HandleShowServerThrottlesCommand);
  52. m_console.Commands.AddCommand(
  53. "Debug", false, "debug lludp packet",
  54. "debug lludp packet [--default | --all] <level> [<avatar-first-name> <avatar-last-name>]",
  55. "Turn on packet debugging. This logs information when the client stack hands a processed packet off to downstream code or when upstream code first requests that a certain packet be sent.",
  56. "If level > 255 then all incoming and outgoing packets are logged.\n"
  57. + "If level <= 255 then incoming AgentUpdate and outgoing SimStats and SimulatorViewerTimeMessage packets are not logged.\n"
  58. + "If level <= 200 then incoming RequestImage and outgoing ImagePacket, ImageData, LayerData and CoarseLocationUpdate packets are not logged.\n"
  59. + "If level <= 100 then incoming ViewerEffect and AgentAnimation and outgoing ViewerEffect and AvatarAnimation packets are not logged.\n"
  60. + "If level <= 50 then outgoing ImprovedTerseObjectUpdate packets are not logged.\n"
  61. + "If level <= 0 then no packets are logged.\n"
  62. + "If --default is specified then the level becomes the default logging level for all subsequent agents.\n"
  63. + "If --all is specified then the level becomes the default logging level for all current and subsequent agents.\n"
  64. + "In these cases, you cannot also specify an avatar name.\n"
  65. + "If an avatar name is given then only packets from that avatar are logged.",
  66. HandlePacketCommand);
  67. m_console.Commands.AddCommand(
  68. "Debug", false, "debug lludp data out",
  69. "debug lludp data out <level> <avatar-first-name> <avatar-last-name>\"",
  70. "Turn on debugging for final outgoing data to the given user's client.",
  71. "This operates at a much lower level than the packet command and prints out available details when the data is actually sent.\n"
  72. + "If level > 0 then information about all outgoing UDP data for this avatar is logged.\n"
  73. + "If level <= 0 then no information about outgoing UDP data for this avatar is logged.",
  74. HandleDataCommand);
  75. m_console.Commands.AddCommand(
  76. "Debug", false, "debug lludp drop",
  77. "debug lludp drop <in|out> <add|remove> <packet-name>",
  78. "Drop all in or outbound packets that match the given name",
  79. "For test purposes.",
  80. HandleDropCommand);
  81. m_console.Commands.AddCommand(
  82. "Debug",
  83. false,
  84. "debug lludp start",
  85. "debug lludp start <in|out|all>",
  86. "Control LLUDP packet processing.",
  87. "No effect if packet processing has already started.\n"
  88. + "in - start inbound processing.\n"
  89. + "out - start outbound processing.\n"
  90. + "all - start in and outbound processing.\n",
  91. HandleStartCommand);
  92. m_console.Commands.AddCommand(
  93. "Debug",
  94. false,
  95. "debug lludp stop",
  96. "debug lludp stop <in|out|all>",
  97. "Stop LLUDP packet processing.",
  98. "No effect if packet processing has already stopped.\n"
  99. + "in - stop inbound processing.\n"
  100. + "out - stop outbound processing.\n"
  101. + "all - stop in and outbound processing.\n",
  102. HandleStopCommand);
  103. m_console.Commands.AddCommand(
  104. "Debug",
  105. false,
  106. "debug lludp pool",
  107. "debug lludp pool <on|off>",
  108. "Turn object pooling within the lludp component on or off.",
  109. HandlePoolCommand);
  110. m_console.Commands.AddCommand(
  111. "Debug",
  112. false,
  113. "debug lludp status",
  114. "debug lludp status",
  115. "Return status of LLUDP packet processing.",
  116. HandleStatusCommand);
  117. m_console.Commands.AddCommand(
  118. "Debug",
  119. false,
  120. "debug lludp throttles log",
  121. "debug lludp throttles log <level> [<avatar-first-name> <avatar-last-name>]",
  122. "Change debug logging level for throttles.",
  123. "If level >= 0 then throttle debug logging is performed.\n"
  124. + "If level <= 0 then no throttle debug logging is performed.",
  125. HandleThrottleCommand);
  126. m_console.Commands.AddCommand(
  127. "Debug",
  128. false,
  129. "debug lludp throttles get",
  130. "debug lludp throttles get [<avatar-first-name> <avatar-last-name>]",
  131. "Return debug settings for throttles.",
  132. "adaptive - true/false, controls adaptive throttle setting.\n"
  133. + "request - request drip rate in kbps.\n"
  134. + "max - the max kbps throttle allowed for the specified existing clients. Use 'debug lludp get new-client-throttle-max' to see the setting for new clients.\n",
  135. HandleThrottleGetCommand);
  136. m_console.Commands.AddCommand(
  137. "Debug",
  138. false,
  139. "debug lludp throttles set",
  140. "debug lludp throttles set <param> <value> [<avatar-first-name> <avatar-last-name>]",
  141. "Set a throttle parameter for the given client.",
  142. "adaptive - true/false, controls adaptive throttle setting.\n"
  143. + "current - current drip rate in kbps.\n"
  144. + "request - requested drip rate in kbps.\n"
  145. + "max - the max kbps throttle allowed for the specified existing clients. Use 'debug lludp set new-client-throttle-max' to change the settings for new clients.\n",
  146. HandleThrottleSetCommand);
  147. m_console.Commands.AddCommand(
  148. "Debug",
  149. false,
  150. "debug lludp get",
  151. "debug lludp get",
  152. "Get debug parameters for the server.",
  153. "max-scene-throttle - the current max cumulative kbps provided for this scene to clients.\n"
  154. + "max-new-client-throttle - the max kbps throttle allowed to new clients. Use 'debug lludp throttles get max' to see the settings for existing clients.",
  155. HandleGetCommand);
  156. m_console.Commands.AddCommand(
  157. "Debug",
  158. false,
  159. "debug lludp set",
  160. "debug lludp set <param> <value>",
  161. "Set a parameter for the server.",
  162. "max-scene-throttle - the current max cumulative kbps provided for this scene to clients.\n"
  163. + "max-new-client-throttle - the max kbps throttle allowed to each new client. Use 'debug lludp throttles set max' to set for existing clients.",
  164. HandleSetCommand);
  165. m_console.Commands.AddCommand(
  166. "Debug",
  167. false,
  168. "debug lludp toggle agentupdate",
  169. "debug lludp toggle agentupdate",
  170. "Toggle whether agentupdate packets are processed or simply discarded.",
  171. HandleAgentUpdateCommand);
  172. }
  173. private void HandleShowServerThrottlesCommand(string module, string[] args)
  174. {
  175. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  176. return;
  177. m_console.OutputFormat("Throttles for {0}", m_udpServer.Scene.Name);
  178. ConsoleDisplayList cdl = new ConsoleDisplayList();
  179. cdl.AddRow("Adaptive throttles", m_udpServer.ThrottleRates.AdaptiveThrottlesEnabled);
  180. long maxSceneDripRate = m_udpServer.Throttle.MaxDripRate;
  181. cdl.AddRow(
  182. "Max scene throttle",
  183. maxSceneDripRate != 0 ? string.Format("{0} kbps", maxSceneDripRate * 8 / 1000) : "unset");
  184. int maxClientDripRate = m_udpServer.ThrottleRates.Total;
  185. cdl.AddRow(
  186. "Max new client throttle",
  187. maxClientDripRate != 0 ? string.Format("{0} kbps", maxClientDripRate * 8 / 1000) : "unset");
  188. m_console.Output(cdl.ToString());
  189. m_console.OutputFormat("{0}\n", GetServerThrottlesReport(m_udpServer));
  190. }
  191. private string GetServerThrottlesReport(LLUDPServer udpServer)
  192. {
  193. StringBuilder report = new StringBuilder();
  194. report.AppendFormat(
  195. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}\n",
  196. "Total",
  197. "Resend",
  198. "Land",
  199. "Wind",
  200. "Cloud",
  201. "Task",
  202. "Texture",
  203. "Asset");
  204. report.AppendFormat(
  205. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}\n",
  206. "kb/s",
  207. "kb/s",
  208. "kb/s",
  209. "kb/s",
  210. "kb/s",
  211. "kb/s",
  212. "kb/s",
  213. "kb/s");
  214. ThrottleRates throttleRates = udpServer.ThrottleRates;
  215. report.AppendFormat(
  216. "{0,7} {1,8} {2,7} {3,7} {4,7} {5,7} {6,9} {7,7}",
  217. (throttleRates.Total * 8) / 1000,
  218. (throttleRates.Resend * 8) / 1000,
  219. (throttleRates.Land * 8) / 1000,
  220. (throttleRates.Wind * 8) / 1000,
  221. (throttleRates.Cloud * 8) / 1000,
  222. (throttleRates.Task * 8) / 1000,
  223. (throttleRates.Texture * 8) / 1000,
  224. (throttleRates.Asset * 8) / 1000);
  225. return report.ToString();
  226. }
  227. protected string GetColumnEntry(string entry, int maxLength, int columnPadding)
  228. {
  229. return string.Format(
  230. "{0,-" + maxLength + "}{1,-" + columnPadding + "}",
  231. entry.Length > maxLength ? entry.Substring(0, maxLength) : entry,
  232. "");
  233. }
  234. private void HandleDataCommand(string module, string[] args)
  235. {
  236. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  237. return;
  238. if (args.Length != 7)
  239. {
  240. MainConsole.Instance.OutputFormat("Usage: debug lludp data out <true|false> <avatar-first-name> <avatar-last-name>");
  241. return;
  242. }
  243. int level;
  244. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[4], out level))
  245. return;
  246. string firstName = args[5];
  247. string lastName = args[6];
  248. m_udpServer.Scene.ForEachScenePresence(sp =>
  249. {
  250. if (sp.Firstname == firstName && sp.Lastname == lastName)
  251. {
  252. MainConsole.Instance.OutputFormat(
  253. "Data debug for {0} ({1}) set to {2} in {3}",
  254. sp.Name, sp.IsChildAgent ? "child" : "root", level, m_udpServer.Scene.Name);
  255. ((LLClientView)sp.ControllingClient).UDPClient.DebugDataOutLevel = level;
  256. }
  257. });
  258. }
  259. private void HandleThrottleCommand(string module, string[] args)
  260. {
  261. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  262. return;
  263. bool all = args.Length == 5;
  264. bool one = args.Length == 7;
  265. if (!all && !one)
  266. {
  267. MainConsole.Instance.OutputFormat(
  268. "Usage: debug lludp throttles log <level> [<avatar-first-name> <avatar-last-name>]");
  269. return;
  270. }
  271. int level;
  272. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, args[4], out level))
  273. return;
  274. string firstName = null;
  275. string lastName = null;
  276. if (one)
  277. {
  278. firstName = args[5];
  279. lastName = args[6];
  280. }
  281. m_udpServer.Scene.ForEachScenePresence(sp =>
  282. {
  283. if (all || (sp.Firstname == firstName && sp.Lastname == lastName))
  284. {
  285. MainConsole.Instance.OutputFormat(
  286. "Throttle log level for {0} ({1}) set to {2} in {3}",
  287. sp.Name, sp.IsChildAgent ? "child" : "root", level, m_udpServer.Scene.Name);
  288. ((LLClientView)sp.ControllingClient).UDPClient.ThrottleDebugLevel = level;
  289. }
  290. });
  291. }
  292. private void HandleThrottleSetCommand(string module, string[] args)
  293. {
  294. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  295. return;
  296. bool all = args.Length == 6;
  297. bool one = args.Length == 8;
  298. if (!all && !one)
  299. {
  300. MainConsole.Instance.OutputFormat(
  301. "Usage: debug lludp throttles set <param> <value> [<avatar-first-name> <avatar-last-name>]");
  302. return;
  303. }
  304. string param = args[4];
  305. string rawValue = args[5];
  306. string firstName = null;
  307. string lastName = null;
  308. if (one)
  309. {
  310. firstName = args[6];
  311. lastName = args[7];
  312. }
  313. if (param == "adaptive")
  314. {
  315. bool newValue;
  316. if (!ConsoleUtil.TryParseConsoleBool(MainConsole.Instance, rawValue, out newValue))
  317. return;
  318. m_udpServer.Scene.ForEachScenePresence(sp =>
  319. {
  320. if (all || (sp.Firstname == firstName && sp.Lastname == lastName))
  321. {
  322. MainConsole.Instance.OutputFormat(
  323. "Setting param {0} to {1} for {2} ({3}) in {4}",
  324. param, newValue, sp.Name, sp.IsChildAgent ? "child" : "root", m_udpServer.Scene.Name);
  325. LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
  326. udpClient.FlowThrottle.AdaptiveEnabled = newValue;
  327. // udpClient.FlowThrottle.MaxDripRate = 0;
  328. // udpClient.FlowThrottle.AdjustedDripRate = 0;
  329. }
  330. });
  331. }
  332. else if (param == "request")
  333. {
  334. int newValue;
  335. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, rawValue, out newValue))
  336. return;
  337. int newCurrentThrottleKbps = newValue * 1000 / 8;
  338. m_udpServer.Scene.ForEachScenePresence(sp =>
  339. {
  340. if (all || (sp.Firstname == firstName && sp.Lastname == lastName))
  341. {
  342. MainConsole.Instance.OutputFormat(
  343. "Setting param {0} to {1} for {2} ({3}) in {4}",
  344. param, newValue, sp.Name, sp.IsChildAgent ? "child" : "root", m_udpServer.Scene.Name);
  345. LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
  346. udpClient.FlowThrottle.RequestedDripRate = newCurrentThrottleKbps;
  347. }
  348. });
  349. }
  350. else if (param == "max")
  351. {
  352. int newValue;
  353. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, rawValue, out newValue))
  354. return;
  355. int newThrottleMaxKbps = newValue * 1000 / 8;
  356. m_udpServer.Scene.ForEachScenePresence(sp =>
  357. {
  358. if (all || (sp.Firstname == firstName && sp.Lastname == lastName))
  359. {
  360. MainConsole.Instance.OutputFormat(
  361. "Setting param {0} to {1} for {2} ({3}) in {4}",
  362. param, newValue, sp.Name, sp.IsChildAgent ? "child" : "root", m_udpServer.Scene.Name);
  363. LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
  364. udpClient.FlowThrottle.MaxDripRate = newThrottleMaxKbps;
  365. }
  366. });
  367. }
  368. }
  369. private void HandleThrottleGetCommand(string module, string[] args)
  370. {
  371. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  372. return;
  373. bool all = args.Length == 4;
  374. bool one = args.Length == 6;
  375. if (!all && !one)
  376. {
  377. MainConsole.Instance.OutputFormat(
  378. "Usage: debug lludp throttles get [<avatar-first-name> <avatar-last-name>]");
  379. return;
  380. }
  381. string firstName = null;
  382. string lastName = null;
  383. if (one)
  384. {
  385. firstName = args[4];
  386. lastName = args[5];
  387. }
  388. m_udpServer.Scene.ForEachScenePresence(sp =>
  389. {
  390. if (all || (sp.Firstname == firstName && sp.Lastname == lastName))
  391. {
  392. m_console.OutputFormat(
  393. "Status for {0} ({1}) in {2}",
  394. sp.Name, sp.IsChildAgent ? "child" : "root", m_udpServer.Scene.Name);
  395. LLUDPClient udpClient = ((LLClientView)sp.ControllingClient).UDPClient;
  396. ConsoleDisplayList cdl = new ConsoleDisplayList();
  397. cdl.AddRow("adaptive", udpClient.FlowThrottle.AdaptiveEnabled);
  398. cdl.AddRow("current", string.Format("{0} kbps", udpClient.FlowThrottle.DripRate * 8 / 1000));
  399. cdl.AddRow("request", string.Format("{0} kbps", udpClient.FlowThrottle.RequestedDripRate * 8 / 1000));
  400. cdl.AddRow("max", string.Format("{0} kbps", udpClient.FlowThrottle.MaxDripRate * 8 / 1000));
  401. m_console.Output(cdl.ToString());
  402. }
  403. });
  404. }
  405. private void HandleGetCommand(string module, string[] args)
  406. {
  407. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  408. return;
  409. m_console.OutputFormat("Debug settings for {0}", m_udpServer.Scene.Name);
  410. ConsoleDisplayList cdl = new ConsoleDisplayList();
  411. long maxSceneDripRate = m_udpServer.Throttle.MaxDripRate;
  412. cdl.AddRow(
  413. "max-scene-throttle",
  414. maxSceneDripRate != 0 ? string.Format("{0} kbps", maxSceneDripRate * 8 / 1000) : "unset");
  415. int maxClientDripRate = m_udpServer.ThrottleRates.Total;
  416. cdl.AddRow(
  417. "max-new-client-throttle",
  418. maxClientDripRate != 0 ? string.Format("{0} kbps", maxClientDripRate * 8 / 1000) : "unset");
  419. m_console.Output(cdl.ToString());
  420. }
  421. private void HandleSetCommand(string module, string[] args)
  422. {
  423. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  424. return;
  425. if (args.Length != 5)
  426. {
  427. MainConsole.Instance.OutputFormat("Usage: debug lludp set <param> <value>");
  428. return;
  429. }
  430. string param = args[3];
  431. string rawValue = args[4];
  432. int newValue;
  433. if (param == "max-scene-throttle")
  434. {
  435. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, rawValue, out newValue))
  436. return;
  437. m_udpServer.Throttle.MaxDripRate = newValue * 1000 / 8;
  438. }
  439. else if (param == "max-new-client-throttle")
  440. {
  441. if (!ConsoleUtil.TryParseConsoleInt(MainConsole.Instance, rawValue, out newValue))
  442. return;
  443. m_udpServer.ThrottleRates.Total = newValue * 1000 / 8;
  444. }
  445. else
  446. {
  447. return;
  448. }
  449. m_console.OutputFormat("{0} set to {1} in {2}", param, rawValue, m_udpServer.Scene.Name);
  450. }
  451. private void HandlePacketCommand(string module, string[] args)
  452. {
  453. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  454. return;
  455. bool setAsDefaultLevel = false;
  456. bool setAll = false;
  457. OptionSet optionSet = new OptionSet()
  458. .Add("default", o => setAsDefaultLevel = (o != null))
  459. .Add("all", o => setAll = (o != null));
  460. List<string> filteredArgs = optionSet.Parse(args);
  461. string name = null;
  462. if (filteredArgs.Count == 6)
  463. {
  464. if (!(setAsDefaultLevel || setAll))
  465. {
  466. name = string.Format("{0} {1}", filteredArgs[4], filteredArgs[5]);
  467. }
  468. else
  469. {
  470. MainConsole.Instance.OutputFormat("ERROR: Cannot specify a user name when setting default/all logging level");
  471. return;
  472. }
  473. }
  474. if (filteredArgs.Count > 3)
  475. {
  476. int newDebug;
  477. if (int.TryParse(filteredArgs[3], out newDebug))
  478. {
  479. if (setAsDefaultLevel || setAll)
  480. {
  481. m_udpServer.DefaultClientPacketDebugLevel = newDebug;
  482. MainConsole.Instance.OutputFormat(
  483. "Packet debug for {0} clients set to {1} in {2}",
  484. (setAll ? "all" : "future"), m_udpServer.DefaultClientPacketDebugLevel, m_udpServer.Scene.Name);
  485. if (setAll)
  486. {
  487. m_udpServer.Scene.ForEachScenePresence(sp =>
  488. {
  489. MainConsole.Instance.OutputFormat(
  490. "Packet debug for {0} ({1}) set to {2} in {3}",
  491. sp.Name, sp.IsChildAgent ? "child" : "root", newDebug, m_udpServer.Scene.Name);
  492. sp.ControllingClient.DebugPacketLevel = newDebug;
  493. });
  494. }
  495. }
  496. else
  497. {
  498. m_udpServer.Scene.ForEachScenePresence(sp =>
  499. {
  500. if (name == null || sp.Name == name)
  501. {
  502. MainConsole.Instance.OutputFormat(
  503. "Packet debug for {0} ({1}) set to {2} in {3}",
  504. sp.Name, sp.IsChildAgent ? "child" : "root", newDebug, m_udpServer.Scene.Name);
  505. sp.ControllingClient.DebugPacketLevel = newDebug;
  506. }
  507. });
  508. }
  509. }
  510. else
  511. {
  512. MainConsole.Instance.Output("Usage: debug lludp packet [--default | --all] 0..255 [<first-name> <last-name>]");
  513. }
  514. }
  515. }
  516. private void HandleDropCommand(string module, string[] args)
  517. {
  518. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  519. return;
  520. if (args.Length != 6)
  521. {
  522. MainConsole.Instance.Output("Usage: debug lludp drop <in|out> <add|remove> <packet-name>");
  523. return;
  524. }
  525. string direction = args[3];
  526. string subCommand = args[4];
  527. string packetName = args[5];
  528. if (subCommand == "add")
  529. {
  530. MainConsole.Instance.OutputFormat(
  531. "Adding packet {0} to {1} drop list for all connections in {2}",
  532. direction, packetName, m_udpServer.Scene.Name);
  533. m_udpServer.Scene.ForEachScenePresence(
  534. sp =>
  535. {
  536. LLClientView llcv = (LLClientView)sp.ControllingClient;
  537. if (direction == "in")
  538. llcv.AddInPacketToDropSet(packetName);
  539. else if (direction == "out")
  540. llcv.AddOutPacketToDropSet(packetName);
  541. }
  542. );
  543. }
  544. else if (subCommand == "remove")
  545. {
  546. MainConsole.Instance.OutputFormat(
  547. "Removing packet {0} from {1} drop list for all connections in {2}",
  548. direction, packetName, m_udpServer.Scene.Name);
  549. m_udpServer.Scene.ForEachScenePresence(
  550. sp =>
  551. {
  552. LLClientView llcv = (LLClientView)sp.ControllingClient;
  553. if (direction == "in")
  554. llcv.RemoveInPacketFromDropSet(packetName);
  555. else if (direction == "out")
  556. llcv.RemoveOutPacketFromDropSet(packetName);
  557. }
  558. );
  559. }
  560. }
  561. private void HandleStartCommand(string module, string[] args)
  562. {
  563. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  564. return;
  565. if (args.Length != 4)
  566. {
  567. MainConsole.Instance.Output("Usage: debug lludp start <in|out|all>");
  568. return;
  569. }
  570. string subCommand = args[3];
  571. if (subCommand == "in" || subCommand == "all")
  572. m_udpServer.StartInbound();
  573. if (subCommand == "out" || subCommand == "all")
  574. m_udpServer.StartOutbound();
  575. }
  576. private void HandleStopCommand(string module, string[] args)
  577. {
  578. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  579. return;
  580. if (args.Length != 4)
  581. {
  582. MainConsole.Instance.Output("Usage: debug lludp stop <in|out|all>");
  583. return;
  584. }
  585. string subCommand = args[3];
  586. if (subCommand == "in" || subCommand == "all")
  587. m_udpServer.StopInbound();
  588. if (subCommand == "out" || subCommand == "all")
  589. m_udpServer.StopOutbound();
  590. }
  591. private void HandlePoolCommand(string module, string[] args)
  592. {
  593. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  594. return;
  595. if (args.Length != 4)
  596. {
  597. MainConsole.Instance.Output("Usage: debug lludp pool <on|off>");
  598. return;
  599. }
  600. string enabled = args[3];
  601. if (enabled == "on")
  602. {
  603. if (m_udpServer.EnablePools())
  604. {
  605. m_udpServer.EnablePoolStats();
  606. MainConsole.Instance.OutputFormat("Packet pools enabled on {0}", m_udpServer.Scene.Name);
  607. }
  608. }
  609. else if (enabled == "off")
  610. {
  611. if (m_udpServer.DisablePools())
  612. {
  613. m_udpServer.DisablePoolStats();
  614. MainConsole.Instance.OutputFormat("Packet pools disabled on {0}", m_udpServer.Scene.Name);
  615. }
  616. }
  617. else
  618. {
  619. MainConsole.Instance.Output("Usage: debug lludp pool <on|off>");
  620. }
  621. }
  622. private void HandleAgentUpdateCommand(string module, string[] args)
  623. {
  624. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  625. return;
  626. m_udpServer.DiscardInboundAgentUpdates = !m_udpServer.DiscardInboundAgentUpdates;
  627. MainConsole.Instance.OutputFormat(
  628. "Discard AgentUpdates now {0} for {1}", m_udpServer.DiscardInboundAgentUpdates, m_udpServer.Scene.Name);
  629. }
  630. private void HandleStatusCommand(string module, string[] args)
  631. {
  632. if (SceneManager.Instance.CurrentScene != null && SceneManager.Instance.CurrentScene != m_udpServer.Scene)
  633. return;
  634. MainConsole.Instance.OutputFormat(
  635. "IN LLUDP packet processing for {0} is {1}", m_udpServer.Scene.Name, m_udpServer.IsRunningInbound ? "enabled" : "disabled");
  636. MainConsole.Instance.OutputFormat(
  637. "OUT LLUDP packet processing for {0} is {1}", m_udpServer.Scene.Name, m_udpServer.IsRunningOutbound ? "enabled" : "disabled");
  638. MainConsole.Instance.OutputFormat("LLUDP pools in {0} are {1}", m_udpServer.Scene.Name, m_udpServer.UsePools ? "on" : "off");
  639. MainConsole.Instance.OutputFormat(
  640. "Packet debug level for new clients is {0}", m_udpServer.DefaultClientPacketDebugLevel);
  641. }
  642. }
  643. }