Compare commits

..

372 Commits

Author SHA1 Message Date
John Gross
814a9def7f Update readme 2019-01-21 16:13:14 -08:00
John Gross
276a4522d6 Disable building Torch client 2019-01-17 10:22:09 -08:00
Brant Martin
8b7a07ffe7 Deprecate ReservedPlayers in Torch cfg
Add a scrollpanel to fix clipped controls
2019-01-10 21:35:48 -05:00
Brant Martin
f990d27851 Enable creation of new worlds in Torch 2019-01-10 19:11:19 -05:00
N1Ran
3d8bf78213 Add Reserved slot and "Auto Detect Dependencies" to config ui plus Torch reserve management oversees all (#269)
* Add server description to config uI and adjusted the mod blocks to fit

* Added checkbox for "Auto detect dependencies" and Reserved players slot.

* Torch reserved slot management is now main and will scan sededi also to match steamid making new config ui addition usable
2019-01-10 09:28:35 -05:00
N1Ran
90479dfea2 Add server description to config uI and adjusted the mod blocks to fit (#268) 2019-01-08 17:30:42 -05:00
Brant Martin
844d4be96a Rearrange client join auth again 2019-01-06 21:21:36 -05:00
John Gross
9f610d5ae8 Merge pull request #266 from sirhamsteralot/master
Add extra functionality to the command system to make dynamic commands remotely plausible
2019-01-01 22:43:18 -08:00
sirhamsteralot
c9adb2a212 add a way to delete nodes from the tree 2018-12-28 02:11:24 +01:00
sirhamsteralot
7fd814d595 fix arrayoutofboundsthing 2018-12-27 23:40:56 +01:00
sirhamsteralot
e7065a7159 forgot to actually fill the parameters 2018-12-27 23:27:47 +01:00
sirhamsteralot
8625db7ae4 fixed nullref crash when invoking 2018-12-27 23:21:29 +01:00
sirhamsteralot
68e6774e26 performed an Exterminatus on code that doesnt work with the new Delegate system. 2018-12-27 23:13:54 +01:00
sirhamsteralot
a7c6ae7382 Invoke the Action directly 2018-12-27 22:57:27 +01:00
sirhamsteralot
9c06049628 Add extra command constructor for easier use of dynamic methods. 2018-12-27 00:57:58 +01:00
Brant Martin
34e5f4df49 Fix #247 in the worst possible way 2018-12-26 13:10:07 -05:00
Brant Martin
b7b58f5870 Add View Distance to torch confix. Resolves #264 2018-12-26 11:52:52 -05:00
Brant Martin
f9d75856d1 Fix some crashes in mod communication 2018-12-26 10:52:54 -05:00
Brant Martin
66b7adf485 Fix mod communication (probably) 2018-12-24 18:02:43 -05:00
Brant Martin
76637b130c Add ban and kick events 2018-12-16 20:53:52 -05:00
Brant Martin
9a1a31c424 Set thread culture to en-US for English exceptions 2018-12-15 20:18:43 -05:00
Brant Martin
faef000245 Fix Family Share banning. 2018-12-15 20:16:44 -05:00
Westin Miller
c2035668cd Async logging 2018-11-04 06:33:14 -08:00
Westin Miller
f1201c6259 Don't add null TryCatchOperations 2018-10-23 14:22:11 -07:00
Brant Martin
bdaa674662 Merge branch 'master' of https://github.com/TorchAPI/Torch 2018-10-23 16:30:15 -04:00
Brant Martin
3b17eb4750 Fix for 188 2018-10-23 16:23:52 -04:00
Westin Miller
9221d412ca Merge branch 'patcher-trycatch' 2018-10-18 18:00:36 -07:00
Brant Martin
65bb71aabf Add reserved slots 2018-10-12 16:12:33 -04:00
Westin Miller
dcd0fa86b9 Add debug symbols to release 2018-10-10 14:25:02 -07:00
Brant Martin
72be1b8dbf Merge branch 'master' of https://github.com/TorchAPI/Torch 2018-10-08 18:00:55 -04:00
Brant Martin
1d7b642c50 Tweak network reflection. Should fix #259 2018-10-08 18:00:40 -04:00
Westin Miller
f7d45ca338 Add more advanced debugging to patcher
Support multiple try-catch operations on a single instruction
Replace long branch with short branch instructions where possible
Dump generated IL at three stages to a file.
2018-10-07 00:44:36 -07:00
John Gross
831722dd84 Add remote API support 2018-09-28 21:48:24 -07:00
Brant Martin
ee3dd0b5bd Fix network injection (Keen broke it) 2018-09-27 10:28:18 -04:00
Brant Martin
7480847677 Add game version to !ver command 2018-09-18 10:42:46 -04:00
Brant Martin
0ff715af1b Remove server password when password field is blank. 2018-08-30 10:07:02 -04:00
a318aa87cf get remote ip fix (#254)
* get remote ip fix

* add GetIp fix to chat command
2018-08-27 22:40:30 -04:00
Brant Martin
74b00d3ab1 Add server password to config UI 2018-08-23 06:38:20 -04:00
Brant Martin
355375e9db Add OnlineMode to session settings. Only allow admins to join an Offline game. 2018-08-20 20:06:32 -04:00
John Gross
016203d2bc Merge pull request #251 from TorchAPI/plugin-asm-resolve
Fix assembly resolving.
2018-08-15 19:10:26 -07:00
Westin Miller
b65efa2968 Fixed error message 2018-08-15 19:07:27 -07:00
Westin Miller
4fc5f10bad Ignore resource assemblies 2018-08-14 16:33:02 -07:00
Westin Miller
f8e9d68ceb Don't unregister plugin assembly resolver. 2018-08-13 19:33:38 -07:00
Brant Martin
65e8d62391 Copy Keen's minidump on crash system. 2018-08-07 08:18:31 -04:00
Westin Miller
93fa82201a Merge pull request #242 from TorchAPI/eq-patcher-locals
Allow prefixes and suffixes to declare shared locals
2018-07-27 07:35:37 -07:00
Westin Miller
71930182dd Allow prefixes and suffixes to declare shared locals 2018-07-27 07:15:55 -07:00
Brant Martin
8764540d3b Set TorchUI window title with InstanceName setting (in torch.cfg) 2018-07-26 23:24:40 -04:00
Brant Martin
6a6676c1cb Revert "Collection editor improvements. Allows reordering of elements, and actually updates the list when content changes."
This reverts commit 14e16a959f.
2018-07-24 21:17:08 -04:00
John Gross
5bf91f1891 Improve UI layout, add flags enum editor to PropertyGrid 2018-07-24 12:51:13 -07:00
Brant Martin
14e16a959f Collection editor improvements. Allows reordering of elements, and actually updates the list when content changes. 2018-07-23 21:50:42 -04:00
John Gross
3b72724966 Update session settings 2018-07-22 10:14:06 -07:00
Brant Martin
9a0e7809cd Fix issue with TorchMod being added to the server config. (also removes TorchMod from any extant config to avoid Problems) 2018-07-20 10:05:08 -04:00
Brant Martin
94c25a70b3 Fix mods not showing up in UI 2018-07-19 21:08:41 -04:00
John Gross
4901120be4 Fix online player list reflection 2018-07-19 14:32:28 -07:00
John Gross
21e45b5e45 Hotfix for assembly loading issues 2018-07-19 11:57:30 -07:00
John Gross
b829e90edb Merge pull request #238 from TorchAPI/experiment
MP Update
2018-07-19 10:18:49 -07:00
Brant Martin
fbf7fa6176 Merge branch 'experiment' of https://github.com/TorchAPI/Torch into experiment 2018-07-18 22:35:23 -04:00
Brant Martin
2b413ef609 Fix mod settings 2018-07-18 22:35:11 -04:00
Brant Martin
0f06ee5688 Disable client IP stuff because it borked 2018-07-18 22:34:59 -04:00
Brant Martin
ec065ec329 Fix network intercept 2018-07-18 22:34:44 -04:00
Brant Martin
c9a5472282 Merge branch 'master' into experiment 2018-07-18 20:24:15 -04:00
Brant Martin
b12199c65b Revert "Let Jenkins download the new branch so the build doesn't blow up"
This reverts commit 4c34a653bd.
2018-07-18 19:38:04 -04:00
Brant Martin
b4ac097910 Revert "SteamCMD is trash"
This reverts commit ebc8b7a7fd.
2018-07-18 19:35:23 -04:00
Brant Martin
aae4ec97a9 Revert "STEAM PLEASE"
This reverts commit 06eca83ff9.
2018-07-18 19:35:22 -04:00
Brant Martin
45d931b351 Revert "I don't even know anymore"
This reverts commit 63f504feb7.
2018-07-18 19:35:20 -04:00
Brant Martin
f53c9660fe Revert "TRY THINGS UNTIL IT WORKS"
This reverts commit b89b61496b.
2018-07-18 19:35:18 -04:00
Brant Martin
c889854818 Minor fixes to client mod 2018-07-18 19:25:08 -04:00
Brant Martin
b8b0a0fcce Make PropertyGrid controls immune from scrollbar wrapping (caused by #218) 2018-07-08 18:25:06 -04:00
Brant Martin
b3f9d7e5c7 Make description box in property grids not clip 2018-07-08 17:46:53 -04:00
Brant Martin
94b457d9c0 Merge pull request #236 from TorchAPI/client-mod
Client mod
2018-07-06 15:30:39 -04:00
Brant Martin
0c58655708 Merge branch 'master' into client-mod 2018-07-06 15:28:15 -04:00
Brant Martin
ba98e0a15a Stop Equinox complaining about session download patch not being static 2018-07-03 18:34:09 -04:00
Brant Martin
5496ad1198 Make get-only collections editable in propertygrid 2018-07-03 14:47:36 -04:00
Brant Martin
7bad6149b5 Refactor ObjectCollectionEditor so it's embeddable in a propertygrid.
Make the listbox actually update when items are added/removed.
2018-07-03 14:47:19 -04:00
Westin Miller
378905268d Update Jenkinsfile
This time remove the correct one.
2018-07-02 08:40:09 -07:00
Westin Miller
f56a700fea Update Jenkinsfile
Remove the client build package.  It was broken anyways.
2018-07-02 08:38:21 -07:00
Brant Martin
736176ce27 Fix custom control type in property grids 2018-07-02 11:27:43 -04:00
John Gross
96d749c512 Merge pull request #234 from SinZ163/fix-231
Disable "Import World Config" button when there are no worlds available
2018-07-01 09:33:14 -07:00
Trent Monahan
17514c89ad Disable ImportWorldConfig when there are no worlds to import 2018-07-01 15:46:07 +10:00
Brant Martin
8b08f2b747 Enable multiline editing of string values in propertygrids 2018-06-23 03:21:45 -04:00
Brant Martin
07bb0fc4cf Merge remote-tracking branch 'origin/master' into client-mod 2018-06-14 18:04:33 -04:00
Brant Martin
dbea9d83f4 Fix crash on exit 2018-06-14 14:15:51 -04:00
Brant Martin
8989ae94a7 Debug output for plugin loading 2018-06-14 11:08:09 -04:00
Brant Martin
4db83e6f65 Add voxel reset message 2018-06-11 07:57:12 -04:00
Westin Miller
9286f2e559 Patch persistent (#232)
Makes it save properly.  Untested push to master :shipit:
2018-06-10 21:46:00 -07:00
Brant Martin
045a572058 Add Torch client mod. Currently supports dialogs and notifications.
Add dialog output to !longhelp
Add !notify command
Silently inserts mod into session when client connects, server admins don't need to do anything to enable it.
2018-06-10 07:31:19 -04:00
Brant Martin
f68be8e4c9 last try 2018-05-16 07:55:51 -04:00
Brant Martin
ec4572c390 VS WHY 2018-05-16 07:49:58 -04:00
Brant Martin
b89b61496b TRY THINGS UNTIL IT WORKS 2018-05-16 07:29:22 -04:00
Brant Martin
63f504feb7 I don't even know anymore 2018-05-16 07:24:33 -04:00
Brant Martin
06eca83ff9 STEAM PLEASE 2018-05-16 07:18:16 -04:00
Brant Martin
ebc8b7a7fd SteamCMD is trash 2018-05-16 07:16:33 -04:00
Brant Martin
4c34a653bd Let Jenkins download the new branch so the build doesn't blow up 2018-05-16 07:14:10 -04:00
Brant Martin
38d2f1b62e Fix for MP 2018-05-16 07:09:05 -04:00
Westin Miller
d8915d1893 Update README.md
Proper download links.
2018-05-13 23:45:07 -07:00
John Gross
873acfcb4f Improve initializer logging 2018-04-29 18:17:17 -07:00
John Gross
030df5029b Merge pull request #229 from TorchAPI/propertygrid
Propertygrid
2018-04-28 10:33:25 -07:00
Brant Martin
7404b6bd2d Fix crash when trying to filter an empty PropertyGrid 2018-04-27 10:26:17 -04:00
Brant Martin
b9e9be227a Tweak DisplayAttribute, don't disable text labels, PropertyGrid should be feature complete now. 2018-04-27 10:25:57 -04:00
Brant Martin
f2537706e7 Allow properties in PropertyGrid to set Enabled, Visible, ReadOnly, override sort order. 2018-04-26 08:20:37 -04:00
John Gross
a8251d9385 Update TorchCommands.cs 2018-04-13 12:09:14 -07:00
John Gross
b1edd62c0b Disallow restart if one is already pending 2018-04-13 12:07:21 -07:00
John Gross
c1e315fa40 Merge pull request #227 from sirhamsteralot/master
Fixed [Theme Bug] #226 / Fixed Crash when plugin has no UI
2018-04-13 12:02:26 -07:00
sirhamsteralot
bfcf96f1ad Disable typing in Log 2018-04-13 20:53:56 +02:00
sirhamsteralot
d257e9e1e8 Fixed crash when plugin doesnt use UI 2018-04-13 20:45:41 +02:00
John Gross
85e307f8db Fix theming for plugins 2018-04-12 18:04:15 -07:00
sirhamsteralot
03fa0a73b6 Changed back to referencing the proper package whoops? 2018-04-12 09:54:34 -07:00
sirhamsteralot
2f157a6438 XML comments 2018-04-12 09:54:34 -07:00
sirhamsteralot
cdde72cbe0 Comments 2018-04-12 09:54:33 -07:00
sirhamsteralot
b18420ad55 Themes apply everywhere now 2018-04-12 09:54:33 -07:00
sirhamsteralot
d92daccdbf I fixed the issue 2018-04-12 09:54:33 -07:00
sirhamsteralot
6b3cc6c421 Save on select 2018-04-12 09:54:32 -07:00
sirhamsteralot
18af85c4d7 Most of these arnt even changes 2018-04-12 09:54:32 -07:00
sirhamsteralot
6c6ff18ec3 Added more themes and serialization of the latest theme 2018-04-12 09:54:32 -07:00
sirhamsteralot
67e663f023 Added Dark themes 2018-04-12 09:54:31 -07:00
sirhamsteralot
3f717b304a Switching Themes is working, just have to create/find a proper theme now 2018-04-12 09:54:31 -07:00
SirHamsterAlot
300af03012 ColoringAttempts 2018-04-12 09:54:30 -07:00
SirHamsterAlot
3d8d333f10 Added Nlog reference 2018-04-12 09:54:30 -07:00
John Gross
d87cc7f1e7 Truncate log in UI, add ability to cancel restart 2018-04-12 09:51:52 -07:00
John Gross
d59ef20f72 Fix config not saving session settings 2018-04-03 11:17:19 -07:00
John Gross
b2bf0229ed Revert FirstOrDefault change 2018-04-03 00:05:32 -07:00
John Gross
f03bfd2d7a Fix suppressed fatal error, make world config importing manual 2018-04-02 21:00:36 -07:00
John Gross
3dd646d6e9 Merge pull request #219 from TorchAPI/GenericUI
Add entity id to grid views
2018-03-21 06:49:59 +01:00
Brant Martin
58ad553b39 Fix data binding direction 2018-03-20 22:47:33 -07:00
Brant Martin
83056bacf4 Add entity id to grid views 2018-03-20 22:47:33 -07:00
John Gross
2751eaf399 Merge pull request #218 from Phoenix84/ScrollViewer
Wrap the plugin controls around a ScrollViewer
2018-03-12 04:39:40 +01:00
Daniel Osborne
869ba0d33c Wrap the plugin controls around a ScrollViewer
So plugin authors don't have to worry about controls drawing out of the
window, wrap the plugin in a ScrollViewer, which will automatically add
a scroll bar if needed.
2018-03-11 20:29:25 -07:00
Westin Miller
aeb29d9a69 Also load symbols from zip files 2018-03-11 07:45:03 -07:00
Westin Miller
979d5914a9 Always try and include debug symbols during plugin load. 2018-03-11 07:39:36 -07:00
John Gross
e72f5b7c37 Fix chat logging and !longhelp permission 2018-02-27 19:19:50 -08:00
John Gross
42d3324fc1 Disable tests on build server 2018-02-21 17:34:06 -08:00
John Gross
e242ed6f1f Disable new world button, fix crash opening plugin folder 2018-02-21 17:19:33 -08:00
Westin Miller
a2acb9c11c Merge pull request #208 from TorchAPI/network-improvement
Tweak client join validation
2018-02-18 22:10:49 -08:00
Brant Martin
444da941c9 Tweak client join validation 2018-02-15 11:14:57 -05:00
Westin Miller
f19fd84f1d Fix empty group letting people in over cap 2018-02-12 14:41:50 -08:00
John Gross
b5793d36a8 Merge pull request #207 from TorchAPI/GenericUI
UI improvements
2018-02-11 20:51:57 -08:00
Brant Martin
a71c03124b Make ObjectCollectionEditor resizable 2018-02-11 23:47:37 -05:00
Brant Martin
66c484796d how about you check in your new files you idiot 2018-02-11 23:24:17 -05:00
Brant Martin
a4927030d7 Let's not require people to press a button to edit primitives 2018-02-11 23:22:30 -05:00
Brant Martin
c32badb750 Add support for Category, Name, and Description to PropertyGrid using DisplayAttribute 2018-02-11 22:43:22 -05:00
John Gross
356eb849f2 Merge pull request #205 from TorchAPI/GenericUI
Add ObjectCollectionEditor
2018-02-09 12:55:26 -08:00
Brant Martin
04e949ed0c Merge branch 'GenericUI' of https://github.com/TorchAPI/Torch into GenericUI 2018-02-09 15:52:27 -05:00
Brant Martin
13dc8622c9 Add ObjectCollectionEditor which allows PropertyGrids to edit any collection of arbitrary objects using yet another PropertyGrid 2018-02-09 15:52:13 -05:00
John Gross
a2b9c4724d Remove text template broken by VRage.Game arch change 2018-02-09 09:18:09 -08:00
Brant Martin
f326e569a1 Add ObjectCollectionEditor which allows PropertyGrids to edit any collection of arbitrary objects using yet another PropertyGrid 2018-02-08 23:34:44 -05:00
John Gross
c1961dee5f Update checkpoint view model 2018-02-02 10:59:21 -08:00
John Gross
e42a231553 Add sane whitelist, fix bad server init logging 2018-01-30 23:40:38 -08:00
John Gross
b3d9a64632 Add validation for world load settings 2018-01-27 09:19:03 -08:00
John Gross
47c7c37fa9 Merge pull request #203 from TorchAPI/character-vm
Character view model and fixed character display
2018-01-26 21:52:45 -08:00
Westin Miller
17413f81ff Character view model and fixed character display 2018-01-26 21:48:46 -08:00
John Gross
725e555733 Merge pull request #201 from TorchAPI/ui-improvements
UI Improvements
2018-01-25 19:10:16 -08:00
John Gross
6e7456605d Allow custom handling of chat command response 2018-01-25 18:34:21 -08:00
John Gross
b652181dda Remove timeouts when waiting for game state changes 2018-01-25 18:34:21 -08:00
John Gross
6764d80534 Enable text wrapping in chat log 2018-01-25 18:34:21 -08:00
John Gross
6fbc06081e Add block limit editor, various UI tweaks 2018-01-25 18:34:21 -08:00
John Gross
0328876d50 More async init, add proper NLog target for WPF and free console in UI mode 2018-01-25 18:34:16 -08:00
John Gross
c5e1dd7c3a Oops, don't init the server twice 2018-01-25 18:33:23 -08:00
John Gross
714824df97 Fix start/stop buttons, improve DS init order, add console tab 2018-01-25 18:33:08 -08:00
John Gross
2cb921087f Remove lazy loading of plugin WPF control 2018-01-25 18:30:23 -08:00
John Gross
1ed3144428 Fix/disable broken tests 2018-01-25 18:30:23 -08:00
John Gross
ba8fa01ce5 Auto-generate configuration dialog, fix logger names, prepare for async initialization 2018-01-25 18:30:23 -08:00
John Gross
3f6f077833 Fix reference path 2018-01-25 18:30:23 -08:00
John Gross
74d9999202 Add informational version type 2018-01-25 18:30:23 -08:00
John Gross
1be1c938cc View model improvements, load world checkpoints for more config options 2018-01-25 18:30:23 -08:00
John Gross
930f1d43e0 Merge pull request #200 from TorchAPI/load-order
Load order
2018-01-25 18:24:06 -08:00
Westin Miller
1e04053026 Let you invoke async on the game thread, just not async blocking.
Fixed event list
2018-01-25 18:19:07 -08:00
Westin Miller
1e6b3faff8 Changed plugins so they get Init-d before the sandbox game is created.
Changed NLog to dump Keen errors to Torch log too
Added some debug info
2018-01-24 17:24:08 -08:00
Westin Miller
e6928b6ab1 Throw error when given the wrong type name 2018-01-15 15:25:53 -08:00
Westin Miller
eb97d0d479 Fixed junction link prompt 2018-01-07 21:57:32 -08:00
Westin Miller
0a75d57cf9 Make async saving as singleton
Don't need an extra Task for save task with no timeout.
2018-01-05 22:08:08 -08:00
Westin Miller
383c9b9a33 Client should work again
™️
2017-12-10 02:46:21 -08:00
Westin Miller
d2adbecc44 Typos 2017-12-10 02:32:59 -08:00
Westin Miller
834395bdc3 Admins can join full servers
Sessions get cleaned up properly
2017-12-05 00:42:03 -08:00
Westin Miller
18dad5bedf Add block count to groups 2017-12-05 00:26:31 -08:00
Westin Miller
c188367749 Observable collection base code for those without a true backing collection.
Observable sorted dictionary
Grid view now displays blocks grouped by subtype.
Null propagation in entity view models because WPF.
2017-12-04 23:52:03 -08:00
Westin Miller
5b098c68aa Session reload stuff
Better async invoke calls for the game thread
2017-12-03 22:27:30 -08:00
Westin Miller
22bd56652d Always force a full reset, to reduce the number of undesired resets. 2017-12-03 22:05:05 -08:00
Westin Miller
d07caea0f6 New saving system with proper waiting for file flush
Command context for servers now supports Respond()
Chat manager now treats the steam ID Sync.MyId as a local destination, and processes the event accordingly.
Save makes better use of Task<>
Restart actually waits for save
PlayerCollectionExtension uses a dictionary lookup for TryGetBySteamId
Shutting the UI window properly closes Torch
Torch Dispose renamed to Destroy, VRage Dispose marked as obsolete (do not use)
2017-12-02 21:19:09 -08:00
Westin Miller
897f75c069 Merge branch 'new_init' 2017-12-02 12:16:30 -08:00
Westin Miller
8167e04383 Merge branch 'staging' 2017-12-02 12:16:23 -08:00
Westin Miller
72b6d0e7bb Tweaks to versioning scheme
Nuke staging
2017-12-02 12:14:48 -08:00
Westin Miller
039c5d9244 Fields on internal types can be reflected 2017-11-25 23:02:01 -08:00
Westin Miller
7ea982c903 Future methods for loading/unloading sessions.
Fix reflected manager to work with instance methods on internal types.
2017-11-25 17:44:50 -08:00
Westin Miller
f0adeddb66 Split game initialization and starting into a separate thread and file. 2017-11-25 17:25:06 -08:00
Westin Miller
e709b6c321 Tweaked initializer to keep the SpaceEngineersGame instance around. 2017-11-25 15:52:53 -08:00
Westin Miller
1b0dcc9808 Validate auth ticket event exposed to other parts of Torch and plugins 2017-11-24 20:46:41 -08:00
John Gross
fe5dfa0ea7 Another restart fix and invoke tweaks 2017-11-23 10:46:28 -08:00
John Gross
25e6f27854 Fixes for 2017-11-17 major 2017-11-17 12:11:11 -08:00
Westin Miller
c07a01a427 Patcher correctly translates catch clauses 2017-11-11 03:50:25 -08:00
Westin Miller
11bc7cb60c Trace level messages
Collection change events are all deferred, and replaced with reset if it makes sense.
2017-11-09 09:42:48 -08:00
Westin Miller
6e3b7e7a04 Merge branch 'fix-dependent-dll-loading' of https://github.com/susu/Torch into staging 2017-11-06 19:42:31 -08:00
Westin Miller
ff58cf5b19 Merge pull request #161 from TorchAPI/plugin-wpf-controls
Pluggable WPF Controls for the Entity Manager UI
2017-11-06 19:36:24 -08:00
Marton Suranyi
25a708a3d4 PluginManager: load dependent DLLs first
When there are dependencies among a plugin's DLLs,
those dependencies needs a custom resolving.
2017-11-06 20:30:48 +01:00
Marton Suranyi
004dcc19dc PluginManager: make zip plugins working
Let Torch to load the plugin's assembly.
2017-11-06 20:28:15 +01:00
Marton Suranyi
ac95f5f89c PluginLoader: load only files with DLL extension from directories and zips
I had several Xy.dll.xml files there
and it was tried to be loaded as an Assembly.
2017-11-06 20:24:09 +01:00
Westin Miller
0fc9b49fba Didn't work well 2017-11-04 10:19:33 -07:00
Westin Miller
600e73ad43 Post transpilers (happen after prefix and suffix)
More debugging options
More robust inline writing and reading
2017-11-04 10:09:22 -07:00
Westin Miller
0bc0b0dc77 Fix integrity analysis to work with loops 2017-11-04 04:18:47 -07:00
Westin Miller
86f62e1f37 Plugin controls are scroll viewers. 2017-11-03 21:16:49 -07:00
Westin Miller
7850b8368a Fix hard clean
Remove leftover logging
2017-11-03 20:15:11 -07:00
Westin Miller
496bde733f Kill repeated file 2017-11-03 19:30:38 -07:00
Westin Miller
8b98deafca Fixed patch manager to emit try-catch-finally blocks.
Solves issue with PBs not running
2017-11-02 22:49:17 -07:00
Westin Miller
b3ab0cbd74 Fix loading plugins from ZIP files 2017-11-01 19:50:02 -07:00
Westin Miller
462eb77e0d Try to load .exe files when looking for assemblies in test framework 2017-11-01 18:19:22 -07:00
Westin Miller
d5702d3065 Progress report when patching 2017-11-01 17:47:21 -07:00
Westin Miller
c8377b318e EntityControlManager partial rewrite to do lazy updating
Auto commit patches once SE instance has been created
2017-11-01 05:08:17 -07:00
Westin Miller
6814a833be Removed some duplicated code. 2017-11-01 01:03:10 -07:00
Westin Miller
98aae10126 Tools for debugging patch transpilers. 2017-10-31 23:42:25 -07:00
Westin Miller
0558675132 If plugins or Torch call the static ctor of MyEntities too early the game doesn't break.
Freeze isn't fatal when compiled with DEBUG.  (So you can use breakpoints)
2017-10-31 20:55:48 -07:00
Westin Miller
c8f42e8a48 Method to determine if a MtObservableCollection is observed by anyone. 2017-10-31 17:39:45 -07:00
Westin Miller
d30d16b855 Fixed issue with not being on dispatcher thread 2017-10-31 04:43:50 -07:00
Westin Miller
178957642c Revert NLog level back to Info 2017-10-31 04:22:10 -07:00
Westin Miller
cd77fe74d5 Pluggable system for providing WPF controls inside the Entity Manager 2017-10-31 04:18:27 -07:00
Westin Miller
90c91c3ebc Initial version of profiler
Moved reflected manager into separate files
Extracted MtObservableEvent
Added a patch to Keencode that lets us call the static cctor of MyEntities in the wrong spot
2017-10-30 13:48:04 -07:00
Westin Miller
11dbf83faf NLog works again 2017-10-30 13:43:35 -07:00
Westin Miller
b7fa57c9b7 Non-indexed remove causes a full reset (@Xero's issue)
Removed ignore last session option.  Implicitly true now.
Asteroid generation options (fixes #151)
2017-10-29 09:53:20 -07:00
Westin Miller
7a63527d8f Archive before test 2017-10-28 00:06:00 -07:00
Westin Miller
4b33bedccd Disable NLog based KeenLog.
NLog is being derpy
2017-10-27 23:28:15 -07:00
Westin Miller
473637ceaf Fixed issue where constructor overloads killed me 2017-10-27 20:10:19 -07:00
Westin Miller
6f5142393b MT observable collections
(UI sync fix)
2017-10-27 17:52:27 -07:00
Westin Miller
fdc20d4e9d Keen's logs now go to Logs/Keen-*
Various formatting options
2017-10-27 14:13:56 -07:00
Westin Miller
4d0dcede41 Log unhandled exceptions very verbosely 2017-10-26 12:41:03 -07:00
Westin Miller
4ed262a330 Report loader exceptions 2017-10-26 12:16:28 -07:00
Westin Miller
48f0f81f12 Hard clean v2 2017-10-26 10:54:19 -07:00
Westin Miller
7b9f2d680a Hard clean 2017-10-26 10:51:56 -07:00
Westin Miller
c69537b173 Warning guard around some unsafe stuff 2017-10-26 10:11:51 -07:00
Westin Miller
794a4a23d3 VRage.Steam snuck in 2017-10-26 09:55:49 -07:00
Westin Miller
998ff6a13a Keen removed infinario 2017-10-26 09:17:36 -07:00
Westin Miller
4ff4a60106 Merge branch 'event-mgr' into staging 2017-10-22 03:31:46 -07:00
Westin Miller
eaaca5b003 Register aux assemblies when they aren't loaded from a zip 2017-10-21 04:21:04 -07:00
Westin Miller
388b4731c7 Merge pull request #137 from TorchAPI/observable-collections
Refactor observable collections and add read-only proxies for them
2017-10-12 02:23:48 -07:00
Westin Miller
f285d67c87 Fixed synchronization in assembly resolver
Close #145
2017-10-10 03:58:21 -07:00
Westin Miller
bc1a612a20 Add server state to ITorchServer
Fixes #101
2017-10-10 03:54:23 -07:00
Westin Miller
b67879577d Remove example shim pending writing actual shims 2017-10-10 03:49:48 -07:00
Westin Miller
2b5b9d44e6 Fix load order issues with reflected manager and patches 2017-10-10 03:08:41 -07:00
Westin Miller
3e48638d8c Merge branch 'app_domains' into event-mgr 2017-10-10 03:01:18 -07:00
Westin Miller
3307d2d23d Patch manager supports communicating method cancel state
Game state patch split out into a patch shim
Special NS for events
Core and auxillary assembly concepts
Reflected manager stops working for mods/scripts
2017-10-10 02:47:45 -07:00
Westin Miller
62d73cbf96 Moved event stuff to a non-manager NS.
Core assembly concept: Assemblies that will never need to get unloaded (Torch.API, Torch, Torch.Server)
Event shims and patch shims on the core assemblies.
2017-10-09 20:52:22 -07:00
Westin Miller
2004f71290 Patch manager state is static, registration methods are non-static.
Patch manager tracks patch context ownership by assembly internally
2017-10-09 01:06:01 -07:00
Westin Miller
013dc43c2f Tagging interface for event handlers
Support events in the TorchAPI
Static registry, non-static registration methods.
Support unregister by assembly.
2017-10-09 00:42:21 -07:00
Westin Miller
716e6cbc04 Event dispatch and registration service 2017-10-08 05:32:16 -07:00
Westin Miller
9e81b6316f Better debugging for freezing 2017-10-05 12:56:16 -07:00
Westin Miller
d709bf68dd New system for resolving binaries 2017-10-04 21:40:42 -07:00
Westin Miller
c14b8ed23a Fixes #138 2017-10-04 18:57:47 -07:00
John Gross
7ba6fb5a2e Add observable read only list implementation 2017-10-03 11:44:35 -07:00
John Gross
4f1a03811a Refactor property changed implementations 2017-10-02 23:44:06 -07:00
John Gross
0946d5a138 Update README.md 2017-09-28 13:57:19 -07:00
Westin Miller
6f650c8bbd More MSIL utilities 2017-09-23 01:29:06 -07:00
John Gross
ad1502e998 Small tweaks 2017-09-22 20:08:47 -07:00
Westin Miller
bb42dd026c Some more misc Msil stuff 2017-09-22 14:45:07 -07:00
Westin Miller
95b6c9dfe5 Fix so plugins properly register commands. 2017-09-22 14:30:21 -07:00
Westin Miller
9b1754a431 Merge pull request #113 from TorchAPI/session-mgr-cmp
Managers for Clients
2017-09-22 00:40:14 -07:00
Westin Miller
0574d59e12 Merge branch 'staging' into session-mgr-cmp 2017-09-22 00:22:45 -07:00
Westin Miller
4f7c35dfcf Use the correct binaries 2017-09-21 23:41:29 -07:00
Westin Miller
967384ccfe Clean before build 2017-09-21 23:07:37 -07:00
John Gross
b906a32e23 Merge pull request #121 from TorchAPI/plugins
Plugin loader improvements
2017-09-21 22:58:02 -07:00
John Gross
9b9a4c5ee1 Merge branch 'staging' into plugins 2017-09-21 22:56:32 -07:00
Westin Miller
13f3e7ee11 Jenkins only releases from master, and builds in Release only on master.
Packages don't contain PDB files on master builds either.
2017-09-21 22:54:48 -07:00
John Gross
b7f2a62b3c Expose read-only collections in PluginManager instead of full collections 2017-09-21 22:30:48 -07:00
John Gross
1f4197ce67 Merge branch 'staging' into plugins 2017-09-21 20:26:32 -07:00
John Gross
f377d044d6 Observable type improvements 2017-09-21 20:15:18 -07:00
Westin Miller
205dd1a201 Merge pull request #120 from blaho/session-mgr-cmp
Exposed information about banned players
2017-09-20 08:24:28 -07:00
Tomas Blaho
9c505c4f5d banned player list made readonly, lobby fakes support 2017-09-20 17:16:15 +02:00
Tomas Blaho
eb7f7f4244 MultiplayerManagerLobby doesn't implement IMultiplayerManagerServer 2017-09-20 17:05:23 +02:00
Tomas Blaho
f1fc49d276 Merge branch 'staging' into session-mgr-cmp
# Conflicts:
#	Torch.API/Managers/IMultiplayerManager.cs
#	Torch/Managers/MultiplayerManager.cs
2017-09-20 16:13:38 +02:00
Tomas Blaho
d8e2072493 documentation added 2017-09-20 13:03:06 +02:00
Tomas Blaho
96f813a17b IMultiplayerManager: added list of banned steam ID's 2017-09-20 12:34:09 +02:00
John Gross
a97542e649 Add "Open Folder" functionality to plugins tab, crash-safe plugin updating 2017-09-14 21:09:20 -07:00
Westin Miller
5eceb21ec7 Comments 2017-09-12 01:44:13 -07:00
Westin Miller
a61b646295 ReflectedMethodInfo allows non-public type names.
MsilInstructionExtensions to make life easier
2017-09-11 22:32:37 -07:00
Westin Miller
373c476d2d Better guessing on the generic operand type 2017-09-11 20:26:33 -07:00
Westin Miller
b1145c8926 Utility method to invert common load and store instructions 2017-09-11 19:50:07 -07:00
Westin Miller
0810e76474 Once the game is created we can patch it with impunity. 2017-09-11 18:55:09 -07:00
Westin Miller
57acb274c6 Don't crash when modifying constructor
Tweak log level of assembly resolver.
Events relating to game initialization and shutdown.
Plugin manager loads plugins right before the dependency manager is attached.
2017-09-11 18:28:53 -07:00
Westin Miller
e57f885d3b Log errors in ReflectedManager 2017-09-11 05:19:02 -07:00
Westin Miller
0073e101dd Fixed issues with operand replacing, and branch instructions. 2017-09-11 05:18:07 -07:00
Westin Miller
b42d43c0e1 Redirect Keen console to Info, all else to trace. 2017-09-11 05:17:21 -07:00
Westin Miller
9d8988a2ec MyLog logs to the Torch logging system
Fixed issue with labels not being transferred correctly when transpiling.
2017-09-10 17:40:43 -07:00
Westin Miller
aa784c121b Null protection in multiplayer manager detach 2017-09-10 15:17:50 -07:00
Westin Miller
a36e8a4065 Merge branch 'staging' into session-mgr-cmp 2017-09-10 15:11:08 -07:00
John Gross
3fd7b66905 Rewrite plugin loader/updater to support loading from .zip and more complex versions. 2017-09-10 01:44:15 -07:00
John Gross
44ebcc5d25 Merge pull request #110 from TorchAPI/patching
Patch Manager
2017-09-10 04:05:50 -04:00
Westin Miller
9a68ed6bd0 Added patching tests
Fixed error when reverting patches
Made the LoggingILGenerator not break without a logger
2017-09-09 23:30:49 -07:00
Westin Miller
4f84cd8963 Normal logging for patch manager
Fix: RE treating constructors as normal methods
2017-09-09 22:15:42 -07:00
Westin Miller
837b56462f Use reflected manager for patch internals 2017-09-09 00:50:45 -07:00
Westin Miller
9c3a22c556 Method patching framework 2017-09-09 00:37:34 -07:00
Westin Miller
9471d83a45 Merge pull request #108 from TorchAPI/staging
Prepare Release v1.2.0
2017-09-07 19:56:23 -07:00
Westin Miller
52b225d944 Merge branch 'master' into staging 2017-09-07 15:39:04 -07:00
Westin Miller
c8f0a61209 Provide DS config path to Save
This keeps MyFileSystem from getting initialized too early.
2017-09-07 14:54:57 -07:00
John Gross
59c3e9eb54 Merge pull request #107 from TorchAPI/patch-96
Proper scrolling and formatting for the ChatPanel.
2017-09-07 13:39:15 -04:00
Westin Miller
d20d68b831 Proper scrolling and formatting for the ChatPanel.
- Users are blue, server is dark blue.
- Autoscroll when it's scrolled to the bottom, else leave it alone.
2017-09-07 02:54:10 -07:00
Westin Miller
cfda1f8eef Fixes issues with the assembly resolver getting disposed when launched in nogui mode.
This should solve #102, #104.
2017-09-07 02:03:48 -07:00
Westin Miller
2fb222125a Merge pull request #106 from TorchAPI/reflected-internals
Specify internal types by Assembly Qualified Name for reflection
2017-09-06 20:58:29 -07:00
John Gross
c7c3c00783 Merge branch 'staging' into reflected-internals 2017-09-06 23:57:34 -04:00
Westin Miller
dcc130e2cf Fixed bad exit code.
Fixed creds GUID
2017-09-06 20:33:37 -07:00
Westin Miller
491f3d3af4 Auto-release 2017-08-31 19:36:01 -07:00
Westin Miller
140000df55 Test-time reflected event checker
Server UI components work with new system
Events for loading and unloading TorchSessions
Commands report information again.
Catch, log, and rethrow errors that occur in Torch-handled SE events
2017-08-31 16:27:55 -07:00
Westin Miller
4b2fee7614 Offline mode fallbacks for the chat manager. 2017-08-31 16:27:54 -07:00
Westin Miller
2c7b522378 Proper delegate naming 2017-08-31 16:27:54 -07:00
Westin Miller
d9ef60d4e8 Client manager components
- ReflectedManager now supports MemberInfo and event replacement
- New chat manager interfaces for both client and server
- New multiplayer manager interfaces for both client and server
2017-08-31 16:27:54 -07:00
Westin Miller
178fcb8164 Specify internal types by Assembly Qualified Name for reflection 2017-08-31 16:22:38 -07:00
John Gross
3d6806b63a Merge pull request #88 from szczepix/patch-1
When path contains spaces
2017-08-31 18:01:00 -04:00
Szczepan Zaskalski
22e3019610 Fixed batch mklink command argument 2017-08-31 22:25:10 +02:00
Szczepan Zaskalski
7937cbd122 When path contains spaces 2017-08-31 22:18:46 +02:00
John Gross
2bef34ee5b Merge pull request #94 from TorchAPI/jenkins
Unified versions.
2017-08-31 01:37:24 -04:00
Westin Miller
efe7236d31 TorchVersion is read-only 2017-08-30 22:35:50 -07:00
Westin Miller
67dba9c820 PluginAttribute now lets you get the version from the loaded assembly
Documentation in PluginAttribute
2017-08-30 14:13:49 -07:00
Westin Miller
52c509aba0 Salt after revision. 2017-08-30 13:38:43 -07:00
Westin Miller
437c7d293e Make local development versions clearly local dev 2017-08-30 11:19:13 -07:00
Westin Miller
2b6ce4f25b Unified versions. 2017-08-29 19:54:06 -07:00
John Gross
64f123abe9 Specify PR base branch 2017-08-27 09:08:50 -07:00
John Gross
599a98bceb Merge pull request #87 from TorchAPI/server-refactor
Server initialization refactor
2017-08-24 23:12:02 -04:00
John Gross
2cd1b8bd4e Merge branch 'staging' into server-refactor
# Conflicts:
#	Torch.Server/Torch.Server.csproj
#	Torch/TorchBase.cs
2017-08-24 17:44:43 -07:00
John Gross
c0be9c25da Refactor server initialization for service support 2017-08-24 17:30:38 -07:00
John Gross
5cea66374f Merge pull request #84 from TorchAPI/jenkins
Generate Assembly Versions on Build
2017-08-23 16:44:29 -04:00
Westin Miller
ee1c270c68 Merge branch 'staging' into jenkins 2017-08-23 03:02:26 -07:00
Westin Miller
4ab08e2faf Automatically create zip file 2017-08-23 01:17:19 -07:00
Westin Miller
dd094edb88 Using UTC time 2017-08-22 23:25:18 -07:00
Westin Miller
56e45236d8 Create empty generated files to MSBuild doesn't freak. 2017-08-22 23:03:44 -07:00
Westin Miller
be9a8c5839 Transform Templates on Build
Templates for all assemblies
2017-08-22 22:31:24 -07:00
John Gross
8c11baf3b9 Merge pull request #81 from TorchAPI/sessions-manager-71
Session Management System
2017-08-22 11:09:04 -04:00
Westin Miller
6ce679bd83 Proper delegate naming 2017-08-22 08:06:30 -07:00
Westin Miller
a4b1b9bb96 CurrentSession available directly from TorchBase
SteamService is now properly injected for clients, and reports errors
Obsolete tags on the manager properties in TorchBase
2017-08-22 08:06:30 -07:00
Westin Miller
91ad78e6a2 Private session field of proper type
Project Setup
2017-08-22 08:06:30 -07:00
Westin Miller
4a68d66ab0 Session management system
- Managers bound to the session instead of to Torch
- TorchSession automatic creation and destruction
- Automatic manager creation for sessions
2017-08-22 08:06:30 -07:00
John Gross
4cb50b556f Merge pull request #80 from TorchAPI/shutdown-crash-fix
Check if thread is running before suspending
2017-08-22 01:31:02 -04:00
John Gross
b5f73a99cc Use Thread.IsAlive property 2017-08-21 20:39:54 -07:00
John Gross
e9476a59e8 Fix ambiguous reference resolution 2017-08-21 20:15:16 -07:00
John Gross
f48f23c2eb Check if thread is running before suspending 2017-08-21 18:57:35 -07:00
John Michael Gross
ddf465d8c9 Merge pull request #79 from TorchAPI/reflection-manager
Testing Framework
2017-08-21 19:38:29 -04:00
Westin Miller
7149287b8e Let's pretend that typo didn't happen. 2017-08-21 15:44:15 -07:00
Westin Miller
cc709c6bb3 Torch.Client.Tests
Fixed jenkinsfile to create reports directory properly
Removed Any CPU configurations from Torch.sln
2017-08-21 15:38:17 -07:00
Westin Miller
8d101c4c11 Many more things use the new reflection system
Project for Torch.Server tests.
Refactoring some of the torch utility classes into a different namespace.
2017-08-20 23:46:19 -07:00
Westin Miller
64eef6cd8e Typo Number 3 2017-08-20 21:56:41 -07:00
Westin Miller
f8ae3c0dd1 Typo Number 2 2017-08-20 21:55:18 -07:00
Westin Miller
589205edc3 :( 2017-08-20 21:50:07 -07:00
Westin Miller
48b212faaf Reflection unit testing
Jenkins integration (we can only hope)
2017-08-20 21:48:42 -07:00
Westin Miller
0554dbc608 Complete documentation for the reflection manager. 2017-08-20 18:30:52 -07:00
Westin Miller
3564eb805c Reflection manager capable of handling field, property, and method resolution. 2017-08-20 17:56:42 -07:00
John Michael Gross
62a8064edd Update README.md 2017-08-20 17:11:49 -07:00
John Michael Gross
55ed45190b Update README.md 2017-08-20 17:09:58 -07:00
Westin Miller
a6ae96093f CI Archiving 2017-08-19 21:49:57 -07:00
Westin Miller
5b1afe6d50 Patch for uninitialized CI directories. 2017-08-19 21:46:29 -07:00
Westin Miller
60df71a74c Merge pull request #77 from TorchAPI/jenkins
Continuous Integration Support
2017-08-19 21:43:18 -07:00
Westin Miller
a6d5da861f Pipeline DSL 2017-08-19 21:36:42 -07:00
Westin Miller
afc10911f7 More descriptive stages 2017-08-19 21:17:58 -07:00
Westin Miller
0686e95c72 Delete existing link 2017-08-19 20:52:03 -07:00
Westin Miller
234754fd49 Initial continuous integration support 2017-08-19 20:31:08 -07:00
John Michael Gross
efb8d0f226 Merge pull request #76 from TorchAPI/dedi-issue-69
Stronger runtime checks in MultiplayerManager and Reflection
2017-08-19 20:13:27 -07:00
Westin Miller
3f881f7d67 Fixed tag parsing in UpdateManager 2017-08-19 18:22:26 -07:00
Westin Miller
64d38abc99 Typo 2017-08-19 18:20:50 -07:00
Westin Miller
4a39362702 Stronger runtime checks in MultiplayerManager and Reflection
MultiplayerManager now uses Keen's wrapper wrapper (wrapper?) of SteamSDK
Removed rogue file in the csproj
2017-08-19 04:56:41 -07:00
John Michael Gross
db2d3794ae Merge pull request #73 from TorchAPI/dedi-issue-69
Multiplayer Authentication Hook Removal
2017-08-19 01:28:38 -07:00
Westin Miller
526ff6fff0 Provide some semblance of compile time checking. 2017-08-18 22:31:03 -07:00
Westin Miller
eebc0e428e Fix that actually fixes the underlying problem with #69 2017-08-18 21:27:09 -07:00
John Michael Gross
80aca514b2 Merge pull request #72 from TorchAPI/dedi-issue-69
Remove player if already registered
2017-08-18 19:52:28 -07:00
Westin Miller
3e8068e82d Fixes a stupid problem with the DS multiplayer not checking if a
player is already registered.  (#69)
2017-08-18 19:34:41 -07:00
John Michael Gross
601fbcd176 Merge pull request #70 from Equinox-/master
Dependency Resolution and Sorting
2017-08-18 16:24:33 -07:00
Westin Miller
40eab15d69 More explanatory naming for Manager Init (Attach) and Dispose (Detach).
Torch.Client uses the registry to discover Steam's installation directory.
2017-08-18 16:19:59 -07:00
Westin Miller
ceb272c0b4 Moved extension classes to seperate files as Jimmacle requires. 2017-08-18 15:30:36 -07:00
Westin Miller
80d4f62694 Added load order restrictions for DependencyAttribute
Abstracted dependency manager away as an interface
2017-08-18 02:03:53 -07:00
Westin Miller
42f58a8649 Recursive dependency trees
- Now TorchBase and TorchSession can each have seperate managers
- Managers now have a Dispose function that's run on shutdown
2017-08-17 23:52:39 -07:00
Westin Miller
6b9af71967 Automatic dependency resolution
- All managers now use automatic dependency resolution
2017-08-17 18:14:23 -07:00
Westin Miller
dbd98a09c5 Early initialization for Torch Client.
- Assembly resolution
- SE installation directory locating
Dependency manager with automatic sorting and resolution
- Drop in replacement for the system currently in TorchBase
Shared binary directory for all Torch projects
2017-08-17 17:32:08 -07:00
John Michael Gross
c6a6363163 Merge pull request #67 from Mavy87/master
Fix to allow Torch to run as a service.
2017-08-17 09:29:04 -07:00
John Gross
82815f66e5 # Torch 1.1.229.265
* Features
    - Added more lenient version parsing for plugins (v#.# should work)
    - Added countdown option to restart command (!restart [seconds])
* Fixes
    - General fixes to work with the latest SE version
    - Fixed config changes not saving
    - Fixed crash on servers using the Windows Classic theme
2017-08-17 09:09:51 -07:00
Rene K
0a38eb770d Fix to allow Torch to run as a service. 2017-08-05 13:06:15 +02:00
John Gross
97da740e7e Catch errors in updater and fix loading error 2017-08-01 13:01:10 -07:00
John Gross
42bb24ca6a Hotfix for save issues 2017-08-01 12:31:49 -07:00
John Gross
2f3b6cdda7 Fix crashes and save issues 2017-07-31 13:12:01 -07:00
John Michael Gross
525b496774 Update README.md 2017-07-26 09:35:43 -07:00
John Michael Gross
562bb77dda Update README.md 2017-07-26 00:57:47 -07:00
281 changed files with 20879 additions and 3798 deletions

6
.gitignore vendored
View File

@@ -1,6 +1,9 @@
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
#Rider directory
.idea/
# User-specific files # User-specific files
*.suo *.suo
*.user *.user
@@ -252,3 +255,6 @@ ModelManifest.xml
# FAKE - F# Make # FAKE - F# Make
.fake/ .fake/
GameBinaries GameBinaries
# Generated Files
**Gen.cs

View File

@@ -1,4 +1,13 @@
# Torch 1.1.205.478 # Torch 1.1.229.265
* Features
- Added more lenient version parsing for plugins (v#.# should work)
- Added countdown option to restart command (!restart [seconds])
* Fixes
- General fixes to work with the latest SE version
- Fixed config changes not saving
- (hopefully) Fixed issue causing crashes on servers using the Windows Classic theme
# Torch 1.1.207.7
* Notes * Notes
- This release makes significant changes to TorchConfig.xml. It has been renamed to Torch.cfg and has different options. - This release makes significant changes to TorchConfig.xml. It has been renamed to Torch.cfg and has different options.
* Features * Features

View File

@@ -1,9 +1,9 @@
# Making a Pull Request # Making a Pull Request
* Fork this repository and make sure your local **master** branch is up to date with the main repository. * Fork this repository and make sure your local **staging** branch is up to date with the main repository.
* Create a new branch for your addition with an appropriate name, e.g. **add-restart-command** * Create a new branch from the **staging** branch for your addition with an appropriate name, e.g. **add-restart-command**
* PRs work by submitting the *entire* branch, so this allows you to continue work without locking up your whole repository. * PRs work by submitting the *entire* branch, so this allows you to continue work without locking up your whole repository.
* Commit your changes to that branch, making sure that you **follow the code guidelines below**. * Commit your changes to that branch, making sure that you **follow the code guidelines below**.
* Submit your branch as a PR to be reviewed. * Submit your branch as a PR to be reviewed, with Torch's **staging** branch as the base.
## Naming Conventions ## Naming Conventions
* Types: **PascalCase** * Types: **PascalCase**

View File

@@ -0,0 +1,22 @@
pushd
$steamData = "C:/Steam/Data/"
$steamCMDPath = "C:/Steam/steamcmd/"
$steamCMDZip = "C:/Steam/steamcmd.zip"
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path $steamData)) {
mkdir "$steamData"
}
if (!(Test-Path $steamCMDPath)) {
if (!(Test-Path $steamCMDZip)) {
(New-Object System.Net.WebClient).DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", "$steamCMDZip");
}
[System.IO.Compression.ZipFile]::ExtractToDirectory($steamCMDZip, $steamCMDPath)
}
cd "$steamData"
& "$steamCMDPath/steamcmd.exe" "+login anonymous" "+force_install_dir $steamData" "+app_update 298740" "+quit"
popd

52
Jenkins/release.ps1 Normal file
View File

@@ -0,0 +1,52 @@
param([string] $ApiBase, [string]$tagName, [string]$authinfo, [string[]] $assetPaths)
Add-Type -AssemblyName "System.Web"
$headers = @{
Authorization = "Basic " + [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($authinfo))
Accept = "application/vnd.github.v3+json"
}
try
{
Write-Output("Checking if release with tag " + $tagName + " already exists...")
$release = Invoke-RestMethod -Uri ($ApiBase+"releases/tags/$tagName") -Method "GET" -Headers $headers
Write-Output(" Using existing release " + $release.id + " at " + $release.html_url)
} catch {
Write-Output(" Doesn't exist")
$rel_arg = @{
tag_name=$tagName
name="Generated $tagName"
body=""
draft=$TRUE
prerelease=$tagName.Contains("alpha") -or $tagName.Contains("beta")
}
Write-Output("Creating new release " + $tagName + "...")
$release = Invoke-RestMethod -Uri ($ApiBase+"releases") -Method "POST" -Headers $headers -Body (ConvertTo-Json($rel_arg))
Write-Output(" Created new release " + $tagName + " at " + $release.html_url)
}
$assetsApiBase = $release.assets_url
Write-Output("Checking for existing assets...")
$existingAssets = Invoke-RestMethod -Uri ($assetsApiBase) -Method "GET" -Headers $headers
$assetLabels = ($assetPaths | ForEach-Object {[System.IO.Path]::GetFileName($_)})
foreach ($asset in $existingAssets) {
if ($assetLabels -contains $asset.name) {
$uri = $asset.url
Write-Output(" Deleting old asset " + $asset.name + " (id " + $asset.id + "); URI=" + $uri)
$result = Invoke-RestMethod -Uri $uri -Method "DELETE" -Headers $headers
}
}
Write-Output("Uploading assets...")
$uploadUrl = $release.upload_url.Substring(0, $release.upload_url.LastIndexOf('{'))
foreach ($asset in $assetPaths) {
$assetName = [System.IO.Path]::GetFileName($asset)
$assetType = [System.Web.MimeMapping]::GetMimeMapping($asset)
$assetData = [System.IO.File]::ReadAllBytes($asset)
$headerExtra = $headers + @{
"Content-Type" = $assetType
Name = $assetName
}
$uri = $uploadUrl + "?name=" + $assetName
Write-Output(" Uploading " + $asset + " as " + $assetType + "; URI=" + $uri)
$result = Invoke-RestMethod -Uri $uri -Method "POST" -Headers $headerExtra -Body $assetData
Write-Output(" ID=" + $result.id + ", found at=" + $result.browser_download_url)
}

73
Jenkinsfile vendored Normal file
View File

@@ -0,0 +1,73 @@
def packageAndArchive(buildMode, packageName, exclude) {
zipFile = "bin\\${packageName}.zip"
packageDir = "bin\\${packageName}\\"
bat "IF EXIST ${zipFile} DEL ${zipFile}"
bat "IF EXIST ${packageDir} RMDIR /S /Q ${packageDir}"
bat "xcopy bin\\x64\\${buildMode} ${packageDir}"
if (exclude.length() > 0) {
bat "del ${packageDir}${exclude}"
}
powershell "Add-Type -Assembly System.IO.Compression.FileSystem; [System.IO.Compression.ZipFile]::CreateFromDirectory(\"\$PWD\\${packageDir}\", \"\$PWD\\${zipFile}\")"
archiveArtifacts artifacts: zipFile, caseSensitive: false, onlyIfSuccessful: true
}
node {
stage('Checkout') {
checkout scm
bat 'git pull --tags'
}
stage('Acquire SE') {
bat 'powershell -File Jenkins/jenkins-grab-se.ps1'
bat 'IF EXIST GameBinaries RMDIR GameBinaries'
bat 'mklink /J GameBinaries "C:/Steam/Data/DedicatedServer64/"'
}
stage('Acquire NuGet Packages') {
bat 'nuget restore Torch.sln'
}
stage('Build') {
currentBuild.description = bat(returnStdout: true, script: '@powershell -File Versioning/version.ps1').trim()
if (env.BRANCH_NAME == "master") {
buildMode = "Release"
} else {
buildMode = "Debug"
}
bat "IF EXIST \"bin\" rmdir /Q /S \"bin\""
bat "IF EXIST \"bin-test\" rmdir /Q /S \"bin-test\""
bat "\"${tool 'MSBuild'}msbuild\" Torch.sln /p:Configuration=${buildMode} /p:Platform=x64 /t:Clean"
bat "\"${tool 'MSBuild'}msbuild\" Torch.sln /p:Configuration=${buildMode} /p:Platform=x64"
}
stage('Archive') {
archiveArtifacts artifacts: "bin/x64/${buildMode}/Torch*", caseSensitive: false, fingerprint: true, onlyIfSuccessful: true
packageAndArchive(buildMode, "torch-server", "Torch.Client*")
/*packageAndArchive(buildMode, "torch-client", "Torch.Server*")*/
}
/* Disabled because they fail builds more often than they detect actual problems
stage('Test') {
bat 'IF NOT EXIST reports MKDIR reports'
bat "\"packages/xunit.runner.console.2.2.0/tools/xunit.console.exe\" \"bin-test/x64/${buildMode}/Torch.Tests.dll\" \"bin-test/x64/${buildMode}/Torch.Server.Tests.dll\" \"bin-test/x64/${buildMode}/Torch.Client.Tests.dll\" -parallel none -xml \"reports/Torch.Tests.xml\""
step([
$class: 'XUnitBuilder',
thresholdMode: 1,
thresholds: [[$class: 'FailedThreshold', failureThreshold: '1']],
tools: [[
$class: 'XUnitDotNetTestType',
deleteOutputFiles: true,
failIfNotNew: true,
pattern: 'reports/*.xml',
skipNoTestFiles: false,
stopProcessingIfError: true
]]
])
}
*/
}

View File

@@ -1,15 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" <nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="logStamp" value="${time} ${pad:padding=-8:inner=[${level:uppercase=true}]}" />
<variable name="logContent" value="${message:withException=true}"/>
<targets> <targets async="true">
<target xsi:type="File" name="main" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" fileName="Logs\Torch-${shortdate}.log" /> <target xsi:type="Null" name="null" formatMessage="false" />
<target xsi:type="File" name="keen" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Keen-${shortdate}.log" />
<target xsi:type="File" name="main" layout="${var:logStamp} ${logger}: ${var:logContent}" fileName="Logs\Torch-${shortdate}.log" />
<target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" /> <target xsi:type="File" name="chat" layout="${longdate} ${message}" fileName="Logs\Chat.log" />
<target xsi:type="ColoredConsole" name="console" layout="${time} [${level:uppercase=true}] ${logger}: ${message}" /> <target xsi:type="ColoredConsole" name="console" layout="${var:logStamp} ${logger:shortName=true}: ${var:logContent}" />
<target xsi:type="File" name="patch" layout="${var:logContent}" fileName="Logs\patch.log"/>
<target xsi:type="FlowDocument" name="wpf" layout="${var:logStamp} ${logger:shortName=true}: ${var:logContent}" />
</targets> </targets>
<rules> <rules>
<logger name="*" minlevel="Info" writeTo="main, console" /> <logger name="Keen" minlevel="Warn" writeTo="main"/>
<logger name="Keen" minlevel="Info" writeTo="console, wpf"/>
<logger name="Keen" minlevel="Debug" writeTo="keen" final="true" />
<logger name="Keen" writeTo="null" final="true" />
<logger name="*" minlevel="Info" writeTo="main, console, wpf" />
<logger name="Chat" minlevel="Info" writeTo="chat" /> <logger name="Chat" minlevel="Info" writeTo="chat" />
<!--<logger name="Torch.Managers.PatchManager.*" minlevel="Trace" writeTo="patch"/>-->
</rules> </rules>
</nlog> </nlog>

View File

@@ -1,31 +1,27 @@
Discord: [![Discord](https://discordapp.com/api/guilds/230191591640268800/widget.png)](https://discord.gg/8uHZykr) [![Discord](https://discordapp.com/api/guilds/230191591640268800/widget.png)](https://discord.gg/8uHZykr) [![Build Status](http://build.torchapi.net/job/Torch/job/Torch/job/master/badge/icon)](http://build.torchapi.net/job/Torch/job/Torch/job/master/)
# What is Torch? # What is Torch?
Torch is the successor to SE Server Extender and gives server admins the tools they need to keep their Space Engineers servers running smoothly. It features a user interface with live management tools and a plugin system so you can run your server exactly how you'd like. Torch is still in early development so there may be bugs and incomplete features. Torch is the successor to SE Server Extender and gives server admins the tools they need to keep their Space Engineers servers running smoothly. It features a user interface with live management tools and a plugin system so you can run your server exactly how you'd like. Torch is still in early development so there may be bugs and incomplete features.
# Features ## Torch.Server
### Features
* WPF-based user interface * WPF-based user interface
* Chat: interact with the game chat and run commands without having to join the game. * Chat: interact with the game chat and run commands without having to join the game.
* Entity manager: realtime modification of ingame entities such as stopping grids and changing block settings without having to join the game * Entity manager: realtime modification of ingame entities such as stopping grids and changing block settings without having to join the game
* Organized, easy to use configuration editor * Organized, easy to use configuration editor
* Extensible using the Torch plugin system * Extensible using the Torch plugin system
### Installation
* Get the latest Torch release here: https://torchapi.net/download
* Unzip the Torch release into its own directory and run the executable. It will automatically download the SE DS and generate the other necessary files.
- If you already have a DS installed you can unzip the Torch files into the folder that contains the DedicatedServer64 folder.
# Building # Building
To build Torch you must first have a complete SE Dedicated installation somewhere. Before you open the solution, run the Setup batch file and enter the path of that installation's DedicatedServer64 folder. The script will make a symlink to that folder so the Torch solution can find the DLL references it needs. To build Torch you must first have a complete SE Dedicated installation somewhere. Before you open the solution, run the Setup batch file and enter the path of that installation's DedicatedServer64 folder. The script will make a symlink to that folder so the Torch solution can find the DLL references it needs.
# Installation Guide
### Automatic (recommended)
* Unzip Torch to its own folder, run Torch.Server.exe and enter 'y' in the prompt for automatic updates. Torch will automatically download the Space Engineers files and generate all of the configs/folders necessary.
### Manual (for hosting companies or the paranoid)
* Install the Space Engineers DS and then unzip the Torch files into the server's DedicatedServer64 directory. It will automatically detect the manual install and disable automatic updates.
In both cases you will need to set the InstancePath in TorchConfig.xml to an existing dedicated server instance as Torch can't fully generate it on its own yet. In both cases you will need to set the InstancePath in TorchConfig.xml to an existing dedicated server instance as Torch can't fully generate it on its own yet.
# Official Plugins If you have a more enjoyable server experience because of Torch, please consider supporting us on Patreon.
Install plugins by unzipping them into the 'Plugins' folder which should be in the same location as the Torch files. If it doesn't exist you can simply create it. [![Patreon](http://i.imgur.com/VzzIMgn.png)](https://www.patreon.com/bePatron?u=847269)!
* [Essentials](https://github.com/TorchAPI/Essentials): Adds a slew of chat commands and other tools to help manage your server.
* [Concealment](https://github.com/TorchAPI/Concealment): Adds game logic and physics optimizations that significantly improve sim speed.
If you have a more enjoyable server experience because of Torch, please consider supporting us on [Patreon](https://www.patreon.com/bePatron?u=847269)!

View File

@@ -3,7 +3,7 @@
@echo off @echo off
set /p path="Please enter the folder location of your SpaceEngineersDedicated.exe: " set /p path="Please enter the folder location of your SpaceEngineersDedicated.exe: "
cd %~dp0 cd %~dp0
mklink /D GameBinaries %path% mklink /J GameBinaries "%path%"
if errorlevel 1 goto Error if errorlevel 1 goto Error
echo Done! You can now open the Torch solution without issue. echo Done! You can now open the Torch solution without issue.
goto End goto End

View File

@@ -0,0 +1,28 @@
using System;
namespace Torch.API.Event
{
/// <summary>
/// Attribute indicating that a method should be invoked when the event occurs.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class EventHandlerAttribute : Attribute
{
/// <summary>
/// Events are executed from low priority to high priority.
/// </summary>
/// <remarks>
/// While this may seem unintuitive this gives the high priority events the final say on changing/canceling events.
/// </remarks>
public int Priority { get; set; } = 0;
/// <summary>
/// Specifies if this handler should ignore a consumed event.
/// </summary>
/// <remarks>
/// If <see cref="SkipCancelled"/> is <em>true</em> and the event is cancelled by a lower priority handler this handler won't be invoked.
/// </remarks>
/// <seealso cref="IEvent.Cancelled"/>
public bool SkipCancelled { get; set; } = false;
}
}

11
Torch.API/Event/IEvent.cs Normal file
View File

@@ -0,0 +1,11 @@
namespace Torch.API.Event
{
public interface IEvent
{
/// <summary>
/// An event that has been cancelled will no be processed in the default manner.
/// </summary>
/// <seealso cref="EventHandlerAttribute.SkipCancelled"/>
bool Cancelled { get; }
}
}

View File

@@ -0,0 +1,9 @@
namespace Torch.API.Event
{
/// <summary>
/// Interface used to tag an event handler. This does <b>not</b> register it with the event manager.
/// </summary>
public interface IEventHandler
{
}
}

View File

@@ -0,0 +1,28 @@
using System.Runtime.CompilerServices;
using Torch.API.Managers;
namespace Torch.API.Event
{
/// <summary>
/// Manager class responsible for registration of event handlers.
/// </summary>
public interface IEventManager : IManager
{
/// <summary>
/// Registers all event handler methods contained in the given instance
/// </summary>
/// <param name="handler">Instance to register</param>
/// <returns><b>true</b> if added, <b>false</b> otherwise</returns>
[MethodImpl(MethodImplOptions.NoInlining)]
bool RegisterHandler(IEventHandler handler);
/// <summary>
/// Unregisters all event handler methods contained in the given instance
/// </summary>
/// <param name="handler">Instance to unregister</param>
/// <returns><b>true</b> if removed, <b>false</b> otherwise</returns>
[MethodImpl(MethodImplOptions.NoInlining)]
bool UnregisterHandler(IEventHandler handler);
}
}

View File

@@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API
{
public interface IChatMessage
{
/// <summary>
/// The time the message was created.
/// </summary>
DateTime Timestamp { get; }
/// <summary>
/// The SteamID of the message author.
/// </summary>
ulong SteamId { get; }
/// <summary>
/// The name of the message author.
/// </summary>
string Name { get; }
/// <summary>
/// The content of the message.
/// </summary>
string Message { get; }
}
}

View File

@@ -1,9 +1,11 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Torch.API.Managers; using Torch.API.Managers;
using Torch.API.Session;
using VRage.Game.ModAPI; using VRage.Game.ModAPI;
namespace Torch.API namespace Torch.API
@@ -16,86 +18,121 @@ namespace Torch.API
/// <summary> /// <summary>
/// Fired when the session begins loading. /// Fired when the session begins loading.
/// </summary> /// </summary>
[Obsolete("Prefer using the TorchSessionManager.SessionStateChanged event")]
event Action SessionLoading; event Action SessionLoading;
/// <summary> /// <summary>
/// Fired when the session finishes loading. /// Fired when the session finishes loading.
/// </summary> /// </summary>
[Obsolete("Prefer using the TorchSessionManager.SessionStateChanged event")]
event Action SessionLoaded; event Action SessionLoaded;
/// <summary> /// <summary>
/// Fires when the session begins unloading. /// Fires when the session begins unloading.
/// </summary> /// </summary>
[Obsolete("Prefer using the TorchSessionManager.SessionStateChanged event")]
event Action SessionUnloading; event Action SessionUnloading;
/// <summary> /// <summary>
/// Fired when the session finishes unloading. /// Fired when the session finishes unloading.
/// </summary> /// </summary>
[Obsolete("Prefer using the TorchSessionManager.SessionStateChanged event")]
event Action SessionUnloaded; event Action SessionUnloaded;
/// <summary>
/// Gets the currently running session instance, or null if none exists.
/// </summary>
ITorchSession CurrentSession { get; }
/// <summary> /// <summary>
/// Configuration for the current instance. /// Configuration for the current instance.
/// </summary> /// </summary>
ITorchConfig Config { get; } ITorchConfig Config { get; }
/// <inheritdoc cref="IMultiplayerManager"/>
IMultiplayerManager Multiplayer { get; }
/// <inheritdoc cref="IPluginManager"/> /// <inheritdoc cref="IPluginManager"/>
[Obsolete]
IPluginManager Plugins { get; } IPluginManager Plugins { get; }
/// <inheritdoc cref="IDependencyManager"/>
IDependencyManager Managers { get; }
[Obsolete("Prefer using Managers.GetManager for global managers")]
T GetManager<T>() where T : class, IManager;
[Obsolete("Prefer using Managers.AddManager for global managers")]
bool AddManager<T>(T manager) where T : class, IManager;
/// <summary> /// <summary>
/// The binary version of the current instance. /// The binary version of the current instance.
/// </summary> /// </summary>
Version TorchVersion { get; } InformationalVersion TorchVersion { get; }
/// <summary> /// <summary>
/// Invoke an action on the game thread. /// Invoke an action on the game thread.
/// </summary> /// </summary>
void Invoke(Action action); void Invoke(Action action, [CallerMemberName] string caller = "");
/// <summary> /// <summary>
/// Invoke an action on the game thread and block until it has completed. /// Invoke an action on the game thread and block until it has completed.
/// If this is called on the game thread the action will execute immediately.
/// </summary> /// </summary>
void InvokeBlocking(Action action); /// <param name="action">Action to execute</param>
/// <param name="caller">Caller of the invoke function</param>
/// <param name="timeoutMs">Timeout before <see cref="TimeoutException"/> is thrown, or -1 to never timeout</param>
/// <exception cref="TimeoutException">If the action times out</exception>
void InvokeBlocking(Action action, int timeoutMs = -1, [CallerMemberName] string caller = "");
/// <summary> /// <summary>
/// Invoke an action on the game thread asynchronously. /// Invoke an action on the game thread asynchronously.
/// </summary> /// </summary>
Task InvokeAsync(Action action); Task InvokeAsync(Action action, [CallerMemberName] string caller = "");
/// <summary> /// <summary>
/// Start the Torch instance. /// Invoke a function on the game thread asynchronously.
/// </summary>
Task<T> InvokeAsync<T>(Func<T> func, [CallerMemberName] string caller = "");
/// <summary>
/// Signals the torch instance to start, then blocks until it's started.
/// </summary> /// </summary>
void Start(); void Start();
/// <summary> /// <summary>
/// Stop the Torch instance. /// Signals the torch instance to stop, then blocks until it's stopped.
/// </summary> /// </summary>
void Stop(); void Stop();
/// <summary> /// <summary>
/// Restart the Torch instance. /// Restart the Torch instance, blocking until the restart has been performed.
/// </summary> /// </summary>
void Restart(); void Restart();
/// <summary> /// <summary>
/// Initializes a save of the game. /// Initializes a save of the game.
/// </summary> /// </summary>
/// <param name="callerId">Id of the player who initiated the save.</param> /// <param name="timeoutMs">timeout before the save is treated as failed, or -1 for no timeout</param>
Task Save(long callerId); /// <param name="exclusive">Only start saving if we aren't already saving</param>
/// <returns>Future result of the save, or null if one is in progress and in exclusive mode</returns>
Task<GameSaveResult> Save(int timeoutMs = -1, bool exclusive = false);
/// <summary> /// <summary>
/// Initialize the Torch instance. /// Initialize the Torch instance. Before this <see cref="Start"/> is invalid.
/// </summary> /// </summary>
void Init(); void Init();
/// <summary> /// <summary>
/// Get an <see cref="IManager"/> that is part of the Torch instance. /// Disposes the Torch instance. After this <see cref="Start"/> is invalid.
/// </summary> /// </summary>
/// <typeparam name="T">Manager type</typeparam> void Destroy();
T GetManager<T>() where T : class, IManager;
/// <summary>
/// The current state of the game this instance of torch is controlling.
/// </summary>
TorchGameState GameState { get; }
/// <summary>
/// Event raised when <see cref="GameState"/> changes.
/// </summary>
event TorchGameStateChangedDel GameStateChanged;
} }
/// <summary> /// <summary>
@@ -103,10 +140,20 @@ namespace Torch.API
/// </summary> /// </summary>
public interface ITorchServer : ITorchBase public interface ITorchServer : ITorchBase
{ {
/// <summary>
/// The current <see cref="ServerState"/>
/// </summary>
ServerState State { get; }
/// <summary> /// <summary>
/// Path of the dedicated instance folder. /// Path of the dedicated instance folder.
/// </summary> /// </summary>
string InstancePath { get; } string InstancePath { get; }
/// <summary>
/// Raised when the server's Init() method has completed.
/// </summary>
event Action<ITorchServer> Initialized;
} }
/// <summary> /// <summary>

View File

@@ -0,0 +1,52 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API
{
/// <summary>
/// Version in the form v#.#.#.#-info
/// </summary>
public class InformationalVersion
{
public Version Version { get; set; }
public string[] Information { get; set; }
public static bool TryParse(string input, out InformationalVersion version)
{
version = default(InformationalVersion);
var trim = input.TrimStart('v');
var info = trim.Split('-');
if (!Version.TryParse(info[0], out Version result))
return false;
version = new InformationalVersion { Version = result };
if (info.Length > 1)
version.Information = info.Skip(1).ToArray();
return true;
}
/// <inheritdoc />
public override string ToString()
{
if (Information == null || Information.Length == 0)
return $"v{Version}";
return $"v{Version}-{string.Join("-", Information)}";
}
public static explicit operator InformationalVersion(Version v)
{
return new InformationalVersion { Version = v };
}
public static implicit operator Version(InformationalVersion v)
{
return v.Version;
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
namespace Torch.API.Managers
{
public static class DependencyManagerExtensions
{
/// <summary>
/// Removes a single manager from this dependency manager.
/// </summary>
/// <param name="managerType">The dependency type to remove</param>
/// <returns>The manager that was removed, or null if one wasn't removed</returns>
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
public static IManager RemoveManager(this IDependencyManager depManager, Type managerType)
{
IManager mgr = depManager.GetManager(managerType);
return depManager.RemoveManager(mgr) ? mgr : null;
}
/// <summary>
/// Removes a single manager from this dependency manager.
/// </summary>
/// <typeparam name="T">The dependency type to remove</typeparam>
/// <returns>The manager that was removed, or null if one wasn't removed</returns>
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
public static IManager RemoveManager<T>(this IDependencyManager depManager)
{
return depManager.RemoveManager(typeof(T));
}
}
}

View File

@@ -0,0 +1,15 @@
namespace Torch.API.Managers
{
public static class DependencyProviderExtensions
{
/// <summary>
/// Gets the manager that provides the given type. If there is no such manager, returns null.
/// </summary>
/// <typeparam name="T">Type of manager</typeparam>
/// <returns>manager, or null if none exists</returns>
public static T GetManager<T>(this IDependencyProvider depProvider) where T : class, IManager
{
return (T)depProvider.GetManager(typeof(T));
}
}
}

View File

@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Engine.Multiplayer;
using Sandbox.Game.Multiplayer;
using VRage.Game;
using VRage.Network;
using VRage.Replication;
namespace Torch.API.Managers
{
/// <summary>
/// Represents a scripted or user chat message.
/// </summary>
public struct TorchChatMessage
{
/// <summary>
/// Creates a new torch chat message with the given author and message.
/// </summary>
/// <param name="author">Author's name</param>
/// <param name="message">Message</param>
/// <param name="font">Font</param>
public TorchChatMessage(string author, string message, string font = MyFontEnum.Blue)
{
Timestamp = DateTime.Now;
AuthorSteamId = null;
Author = author;
Message = message;
Font = font;
}
/// <summary>
/// Creates a new torch chat message with the given author and message.
/// </summary>
/// <param name="author">Author's name</param>
/// <param name="authorSteamId">Author's steam ID</param>
/// <param name="message">Message</param>
/// <param name="font">Font</param>
public TorchChatMessage(string author, ulong authorSteamId, string message, string font = MyFontEnum.Blue)
{
Timestamp = DateTime.Now;
AuthorSteamId = authorSteamId;
Author = author;
Message = message;
Font = font;
}
/// <summary>
/// Creates a new torch chat message with the given author and message.
/// </summary>
/// <param name="authorSteamId">Author's steam ID</param>
/// <param name="message">Message</param>
/// <param name="font">Font</param>
public TorchChatMessage(ulong authorSteamId, string message, string font = MyFontEnum.Blue)
{
Timestamp = DateTime.Now;
AuthorSteamId = authorSteamId;
Author = MyMultiplayer.Static?.GetMemberName(authorSteamId) ?? "Player";
Message = message;
Font = font;
}
/// <summary>
/// This message's timestamp.
/// </summary>
public readonly DateTime Timestamp;
/// <summary>
/// The author's steam ID, if available. Else, null.
/// </summary>
public readonly ulong? AuthorSteamId;
/// <summary>
/// The author's name, if available. Else, null.
/// </summary>
public readonly string Author;
/// <summary>
/// The message contents.
/// </summary>
public readonly string Message;
/// <summary>
/// The font, or null if default.
/// </summary>
public readonly string Font;
}
/// <summary>
/// Callback used to indicate that a messaage has been recieved.
/// </summary>
/// <param name="msg"></param>
/// <param name="consumed">If true, this event has been consumed and should be ignored</param>
public delegate void MessageRecievedDel(TorchChatMessage msg, ref bool consumed);
/// <summary>
/// Callback used to indicate the user is attempting to send a message locally.
/// </summary>
/// <param name="msg">Message the user is attempting to send</param>
/// <param name="consumed">If true, this event has been consumed and should be ignored</param>
public delegate void MessageSendingDel(string msg, ref bool consumed);
public interface IChatManagerClient : IManager
{
/// <summary>
/// Event that is raised when a message addressed to us is recieved. <see cref="MessageRecievedDel"/>
/// </summary>
event MessageRecievedDel MessageRecieved;
/// <summary>
/// Event that is raised when we are attempting to send a message. <see cref="MessageSendingDel"/>
/// </summary>
event MessageSendingDel MessageSending;
/// <summary>
/// Triggers the <see cref="MessageSending"/> event,
/// typically raised by the user entering text into the chat window.
/// </summary>
/// <param name="message">The message to send</param>
void SendMessageAsSelf(string message);
/// <summary>
/// Displays a message on the UI given an author name and a message.
/// </summary>
/// <param name="author">Author name</param>
/// <param name="message">Message content</param>
/// <param name="font">font to use</param>
void DisplayMessageOnSelf(string author, string message, string font = "Blue" );
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VRage.Network;
namespace Torch.API.Managers
{
/// <summary>
/// Callback used to indicate the server has recieved a message to process and forward on to others.
/// </summary>
/// <param name="authorId">Steam ID of the user sending a message</param>
/// <param name="msg">Message the user is attempting to send</param>
/// <param name="consumed">If true, this event has been consumed and should be ignored</param>
public delegate void MessageProcessingDel(TorchChatMessage msg, ref bool consumed);
public interface IChatManagerServer : IChatManagerClient
{
/// <summary>
/// Event triggered when the server has recieved a message and should process it. <see cref="MessageProcessingDel"/>
/// </summary>
event MessageProcessingDel MessageProcessing;
/// <summary>
/// Sends a message with the given author and message to the given player, or all players by default.
/// </summary>
/// <param name="authorId">Author's steam ID</param>
/// <param name="message">The message to send</param>
/// <param name="targetSteamId">Player to send the message to, or everyone by default</param>
void SendMessageAsOther(ulong authorId, string message, ulong targetSteamId = 0);
/// <summary>
/// Sends a scripted message with the given author and message to the given player, or all players by default.
/// </summary>
/// <param name="author">Author name</param>
/// <param name="message">The message to send</param>
/// <param name="font">Font to use</param>
/// <param name="targetSteamId">Player to send the message to, or everyone by default</param>
void SendMessageAsOther(string author, string message, string font, ulong targetSteamId = 0);
}
}

View File

@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API.Managers
{
/// <summary>
/// Manages a set of <see cref="IManager"/> and the dependencies between them.
/// </summary>
public interface IDependencyManager : IDependencyProvider
{
/// <summary>
/// Registers the given manager into the dependency system.
/// </summary>
/// <remarks>
/// This method only returns false when there is already a manager registered with a type derived from this given manager,
/// or when the given manager is derived from an already existing manager.
/// </remarks>
/// <param name="manager">Manager to register</param>
/// <exception cref="InvalidOperationException">When adding a new manager to an initialized dependency manager</exception>
/// <returns>true if added, false if not</returns>
bool AddManager(IManager manager);
/// <summary>
/// Clears all managers registered with this dependency manager
/// </summary>
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
void ClearManagers();
/// <summary>
/// Removes a single manager from this dependency manager.
/// </summary>
/// <param name="manager">The manager to remove</param>
/// <returns>true if successful, false if the manager wasn't found</returns>
/// <exception cref="InvalidOperationException">When removing managers from an initialized dependency manager</exception>
bool RemoveManager(IManager manager);
/// <summary>
/// Sorts the dependency manager, then attaches all its registered managers in <see cref="AttachOrder" />
/// </summary>
void Attach();
/// <summary>
/// Detaches all registered managers in <see cref="DetachOrder"/>
/// </summary>
void Detach();
/// <summary>
/// The order that managers should be attached in. (Dependencies, then dependents)
/// </summary>
/// <exception cref="InvalidOperationException">When trying to determine load order before this dependency manager is initialized</exception>
IEnumerable<IManager> AttachOrder { get; }
/// <summary>
/// The order that managers should be detached in. (Dependents, then dependencies)
/// </summary>
/// <exception cref="InvalidOperationException">When trying to determine unload order before this dependency manager is initialized</exception>
IEnumerable<IManager> DetachOrder { get; }
}
}

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API.Managers
{
public interface IDependencyProvider
{
/// <summary>
/// Gets the manager that provides the given type. If there is no such manager, returns null.
/// </summary>
/// <param name="type">Type of manager</param>
/// <returns>manager, or null if none exists</returns>
IManager GetManager(Type type);
}
}

View File

@@ -12,8 +12,13 @@ namespace Torch.API.Managers
public interface IManager public interface IManager
{ {
/// <summary> /// <summary>
/// Initializes the manager. Called after Torch is initialized. /// Attaches the manager to the session. Called once this manager's dependencies have been attached.
/// </summary> /// </summary>
void Init(); void Attach();
/// <summary>
/// Detaches the manager from the session. Called before this manager's dependencies are detached.
/// </summary>
void Detach();
} }
} }

View File

@@ -1,61 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using VRage.Game;
using VRage.Game.ModAPI;
namespace Torch.API.Managers
{
/// <summary>
/// Delegate for received messages.
/// </summary>
/// <param name="message">Message data.</param>
/// <param name="sendToOthers">Flag to broadcast message to other players.</param>
public delegate void MessageReceivedDel(IChatMessage message, ref bool sendToOthers);
/// <summary>
/// API for multiplayer related functions.
/// </summary>
public interface IMultiplayerManager : IManager
{
/// <summary>
/// Fired when a player joins.
/// </summary>
event Action<IPlayer> PlayerJoined;
/// <summary>
/// Fired when a player disconnects.
/// </summary>
event Action<IPlayer> PlayerLeft;
/// <summary>
/// Fired when a chat message is received.
/// </summary>
event MessageReceivedDel MessageReceived;
/// <summary>
/// Send a chat message to all or one specific player.
/// </summary>
void SendMessage(string message, string author = "Server", long playerId = 0, string font = MyFontEnum.Blue);
/// <summary>
/// Kicks the player from the game.
/// </summary>
void KickPlayer(ulong steamId);
/// <summary>
/// Bans or unbans a player from the game.
/// </summary>
void BanPlayer(ulong steamId, bool banned = true);
/// <summary>
/// Gets a player by their Steam64 ID or returns null if the player isn't found.
/// </summary>
IMyPlayer GetPlayerBySteamId(ulong id);
/// <summary>
/// Gets a player by their display name or returns null if the player isn't found.
/// </summary>
IMyPlayer GetPlayerByName(string name);
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using VRage.Game;
using VRage.Game.ModAPI;
namespace Torch.API.Managers
{
/// <summary>
/// API for multiplayer related functions common to servers and clients.
/// </summary>
public interface IMultiplayerManagerBase : IManager
{
/// <summary>
/// Fired when a player joins.
/// </summary>
event Action<IPlayer> PlayerJoined;
/// <summary>
/// Fired when a player disconnects.
/// </summary>
event Action<IPlayer> PlayerLeft;
/// <summary>
/// Gets a player by their Steam64 ID or returns null if the player isn't found.
/// </summary>
IMyPlayer GetPlayerBySteamId(ulong id);
/// <summary>
/// Gets a player by their display name or returns null if the player isn't found.
/// </summary>
IMyPlayer GetPlayerByName(string name);
/// <summary>
/// Gets the steam username of a member's steam ID
/// </summary>
/// <param name="steamId">steam ID</param>
/// <returns>steam username</returns>
string GetSteamUsername(ulong steamId);
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API.Managers
{
public interface IMultiplayerManagerClient : IMultiplayerManagerBase
{
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API.Managers
{
/// <summary>
/// API for multiplayer functions that exist on servers and lobbies
/// </summary>
public interface IMultiplayerManagerServer : IMultiplayerManagerBase
{
/// <summary>
/// Kicks the player from the game.
/// </summary>
void KickPlayer(ulong steamId);
/// <summary>
/// Bans or unbans a player from the game.
/// </summary>
void BanPlayer(ulong steamId, bool banned = true);
/// <summary>
/// List of the banned SteamID's
/// </summary>
IReadOnlyList<ulong> BannedPlayers { get; }
/// <summary>
/// Checks if the player with the given SteamID is banned.
/// </summary>
/// <param name="steamId">The SteamID of the player.</param>
/// <returns>True if the player is banned; otherwise false.</returns>
bool IsBanned(ulong steamId);
/// <summary>
/// Raised when a player is kicked. Passes with SteamID of kicked player.
/// </summary>
event Action<ulong> PlayerKicked;
/// <summary>
/// Raised when a player is banned or unbanned. Passes SteamID of player, and true if banned, false if unbanned.
/// </summary>
event Action<ulong, bool> PlayerBanned;
}
}

View File

@@ -18,6 +18,12 @@ namespace Torch.API.Managers
/// Register a network handler. /// Register a network handler.
/// </summary> /// </summary>
void RegisterNetworkHandler(INetworkHandler handler); void RegisterNetworkHandler(INetworkHandler handler);
/// <summary>
/// Unregister a network handler.
/// </summary>
/// <returns>true if the handler was unregistered, false if it wasn't registered to begin with</returns>
bool UnregisterNetworkHandler(INetworkHandler handler);
} }
/// <summary> /// <summary>
@@ -33,6 +39,7 @@ namespace Torch.API.Managers
/// <summary> /// <summary>
/// Processes a network message. /// Processes a network message.
/// </summary> /// </summary>
/// <returns>true if the message should be discarded</returns>
bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj, MyPacket packet); bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj, MyPacket packet);
} }
} }

View File

@@ -14,23 +14,18 @@ namespace Torch.API.Managers
/// <summary> /// <summary>
/// Fired when plugins are loaded. /// Fired when plugins are loaded.
/// </summary> /// </summary>
event Action<IList<ITorchPlugin>> PluginsLoaded; event Action<IReadOnlyCollection<ITorchPlugin>> PluginsLoaded;
/// <summary> /// <summary>
/// Collection of loaded plugins. /// Collection of loaded plugins.
/// </summary> /// </summary>
IList<ITorchPlugin> Plugins { get; } IReadOnlyDictionary<Guid, ITorchPlugin> Plugins { get; }
/// <summary> /// <summary>
/// Updates all loaded plugins. /// Updates all loaded plugins.
/// </summary> /// </summary>
void UpdatePlugins(); void UpdatePlugins();
/// <summary>
/// Disposes all loaded plugins.
/// </summary>
void DisposePlugins();
/// <summary> /// <summary>
/// Load plugins. /// Load plugins.
/// </summary> /// </summary>

View File

@@ -17,7 +17,7 @@ namespace Torch.API.Plugins
/// <summary> /// <summary>
/// The version of the plugin. /// The version of the plugin.
/// </summary> /// </summary>
Version Version { get; } string Version { get; }
/// <summary> /// <summary>
/// The name of the plugin. /// The name of the plugin.

View File

@@ -1,22 +1,56 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Torch.API.Plugins namespace Torch.API.Plugins
{ {
/// <summary>
/// Indicates that the given type should be loaded by the plugin manager as a plugin.
/// </summary>
[Obsolete("All plugin meta-information is now defined in the manifest.xml.")]
[AttributeUsage(AttributeTargets.Class)]
public class PluginAttribute : Attribute public class PluginAttribute : Attribute
{ {
/// <summary>
/// The display name of the plugin
/// </summary>
public string Name { get; } public string Name { get; }
/// <summary>
/// The version of the plugin
/// </summary>
public Version Version { get; } public Version Version { get; }
/// <summary>
/// The GUID of the plugin
/// </summary>
public Guid Guid { get; } public Guid Guid { get; }
/// <summary>
/// Creates a new plugin attribute with the given attributes
/// </summary>
/// <param name="name"></param>
/// <param name="version"></param>
/// <param name="guid"></param>
public PluginAttribute(string name, string version, string guid) public PluginAttribute(string name, string version, string guid)
{ {
Name = name; Name = name;
Version = Version.Parse(version); Version = Version.Parse(version);
Guid = Guid.Parse(guid); Guid = Guid.Parse(guid);
} }
/// <summary>
/// Creates a new plugin attribute with the given attributes. Version is computed as the version of the assembly containing the given type.
/// </summary>
/// <param name="name"></param>
/// <param name="versionSupplier">Version is this type's assembly's version</param>
/// <param name="guid"></param>
public PluginAttribute(string name, Type versionSupplier, string guid)
{
Name = name;
Version = versionSupplier.Assembly.GetName().Version;
Guid = Guid.Parse(guid);
}
} }
} }

View File

@@ -1,36 +1,17 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following [assembly: AssemblyTitle("Torch API")]
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TorchAPI")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TorchAPI")] [assembly: AssemblyProduct("Torch")]
[assembly: AssemblyCopyright("Copyright © 2016")] [assembly: AssemblyCopyright("Copyright © Torch API 2017")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM #if DEBUG
[assembly: Guid("fba5d932-6254-4a1e-baf4-e229fa94e3c2")] [assembly: AssemblyConfiguration("Debug")]
#else
// Version information for an assembly consists of the following four values: [assembly: AssemblyConfiguration("Release")]
// #endif
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API.Session
{
/// <summary>
/// The result of a save operation
/// </summary>
public enum GameSaveResult
{
/// <summary>
/// Successfully saved
/// </summary>
Success = 0,
/// <summary>
/// The game wasn't ready to be saved
/// </summary>
GameNotReady = -1,
/// <summary>
/// Failed to take the snapshot of the current world state
/// </summary>
FailedToTakeSnapshot = -2,
/// <summary>
/// Failed to save the snapshot to disk
/// </summary>
FailedToSaveToDisk = -3,
/// <summary>
/// An unknown error occurred
/// </summary>
UnknownError = -4,
/// <summary>
/// The save operation timed out
/// </summary>
TimedOut = -5
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Game.World;
using Torch.API.Managers;
namespace Torch.API.Session
{
/// <summary>
/// Represents the Torch code working with a single game session
/// </summary>
public interface ITorchSession
{
/// <summary>
/// The Torch instance this session is bound to
/// </summary>
ITorchBase Torch { get; }
/// <summary>
/// The Space Engineers game session this session is bound to.
/// </summary>
MySession KeenSession { get; }
/// <inheritdoc cref="IDependencyManager"/>
IDependencyManager Managers { get; }
/// <summary>
/// The current state of the session
/// </summary>
TorchSessionState State { get; }
/// <summary>
/// Event raised when the <see cref="State"/> changes.
/// </summary>
event TorchSessionStateChangedDel StateChanged;
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Torch.API.Managers;
namespace Torch.API.Session
{
/// <summary>
/// Creates a manager for the given session if applicable.
/// </summary>
/// <remarks>
/// This is for creating managers that will live inside the session, not the manager that controls sesssions.
/// </remarks>
/// <param name="session">The session to construct a bound manager for</param>
/// <returns>The manager that will live in the session, or null if none.</returns>
public delegate IManager SessionManagerFactoryDel(ITorchSession session);
/// <summary>
/// Manages the creation and destruction of <see cref="ITorchSession"/> instances for each <see cref="Sandbox.Game.World.MySession"/> created by Space Engineers.
/// </summary>
public interface ITorchSessionManager : IManager
{
/// <summary>
/// The currently running session
/// </summary>
ITorchSession CurrentSession { get; }
/// <summary>
/// Raised when any <see cref="ITorchSession"/> <see cref="ITorchSession.State"/> changes.
/// </summary>
event TorchSessionStateChangedDel SessionStateChanged;
/// <summary>
/// Adds the given factory as a supplier for session based managers
/// </summary>
/// <param name="factory">Session based manager supplier</param>
/// <returns>true if added, false if already present</returns>
/// <exception cref="ArgumentNullException">If the factory is null</exception>
bool AddFactory(SessionManagerFactoryDel factory);
/// <summary>
/// Remove the given factory from the suppliers for session based managers
/// </summary>
/// <param name="factory">Session based manager supplier</param>
/// <returns>true if removed, false if not present</returns>
/// <exception cref="ArgumentNullException">If the factory is null</exception>
bool RemoveFactory(SessionManagerFactoryDel factory);
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.API.Session
{
/// <summary>
/// Represents the state of a <see cref="ITorchSession"/>
/// </summary>
public enum TorchSessionState
{
/// <summary>
/// The session has been created, and is now loading.
/// </summary>
Loading,
/// <summary>
/// The session has loaded, and is now running.
/// </summary>
Loaded,
/// <summary>
/// The session was running, and is now unloading.
/// </summary>
Unloading,
/// <summary>
/// The session was unloading, and is now unloaded and stopped.
/// </summary>
Unloaded
}
/// <summary>
/// Callback raised when a session's state changes
/// </summary>
/// <param name="session">The session who had a state change</param>
/// <param name="newState">The session's new state</param>
public delegate void TorchSessionStateChangedDel(ITorchSession session, TorchSessionState newState);
}

View File

@@ -2,8 +2,6 @@
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}</ProjectGuid> <ProjectGuid>{FBA5D932-6254-4A1E-BAF4-E229FA94E3C2}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
@@ -12,10 +10,12 @@
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath> <OutputPath>$(SolutionDir)\bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
@@ -23,14 +23,14 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath> <OutputPath>$(SolutionDir)\bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>bin\x64\Release\Torch.API.xml</DocumentationFile> <DocumentationFile>$(SolutionDir)\bin\x64\Release\Torch.API.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="HavokWrapper, Version=1.0.6278.22649, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="HavokWrapper, Version=1.0.6278.22649, Culture=neutral, processorArchitecture=AMD64">
@@ -38,8 +38,8 @@
<HintPath>..\GameBinaries\HavokWrapper.dll</HintPath> <HintPath>..\GameBinaries\HavokWrapper.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="NLog"> <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.1\lib\net45\NLog.dll</HintPath> <HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
@@ -74,11 +74,6 @@
<HintPath>..\GameBinaries\SpaceEngineers.ObjectBuilders.XmlSerializers.dll</HintPath> <HintPath>..\GameBinaries\SpaceEngineers.ObjectBuilders.XmlSerializers.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="SteamSDK, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\GameBinaries\SteamSDK.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" /> <Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@@ -156,12 +151,27 @@
</Reference> </Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="..\Versioning\AssemblyVersion.cs">
<Link>Properties\AssemblyVersion.cs</Link>
</Compile>
<Compile Include="ConnectionState.cs" /> <Compile Include="ConnectionState.cs" />
<Compile Include="IChatMessage.cs" /> <Compile Include="InformationalVersion.cs" />
<Compile Include="ITorchConfig.cs" /> <Compile Include="ITorchConfig.cs" />
<Compile Include="Managers\DependencyManagerExtensions.cs" />
<Compile Include="Managers\DependencyProviderExtensions.cs" />
<Compile Include="Event\EventHandlerAttribute.cs" />
<Compile Include="Event\IEvent.cs" />
<Compile Include="Event\IEventHandler.cs" />
<Compile Include="Managers\IChatManagerClient.cs" />
<Compile Include="Managers\IChatManagerServer.cs" />
<Compile Include="Managers\IDependencyManager.cs" />
<Compile Include="Managers\IDependencyProvider.cs" />
<Compile Include="Event\IEventManager.cs" />
<Compile Include="Managers\IManager.cs" /> <Compile Include="Managers\IManager.cs" />
<Compile Include="Managers\IMultiplayerManager.cs" /> <Compile Include="Managers\IMultiplayerManagerClient.cs" />
<Compile Include="Managers\IMultiplayerManagerBase.cs" />
<Compile Include="IPlayer.cs" /> <Compile Include="IPlayer.cs" />
<Compile Include="Managers\IMultiplayerManagerServer.cs" />
<Compile Include="Managers\INetworkManager.cs" /> <Compile Include="Managers\INetworkManager.cs" />
<Compile Include="Managers\IPluginManager.cs" /> <Compile Include="Managers\IPluginManager.cs" />
<Compile Include="Plugins\ITorchPlugin.cs" /> <Compile Include="Plugins\ITorchPlugin.cs" />
@@ -173,16 +183,19 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServerState.cs" /> <Compile Include="ServerState.cs" />
<Compile Include="ModAPI\TorchAPI.cs" /> <Compile Include="ModAPI\TorchAPI.cs" />
<Compile Include="Session\GameSaveResult.cs" />
<Compile Include="Session\ITorchSession.cs" />
<Compile Include="Session\ITorchSessionManager.cs" />
<Compile Include="Session\TorchSessionState.cs" />
<Compile Include="TorchGameState.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <Import Project="$(SolutionDir)\TransformOnBuild.targets" />
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project> </Project>

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox;
namespace Torch.API
{
/// <summary>
/// Represents the state of a <see cref="MySandboxGame"/>
/// </summary>
public enum TorchGameState
{
/// <summary>
/// The game is currently being created.
/// </summary>
Creating,
/// <summary>
/// The game has been created and is ready to begin loading.
/// </summary>
Created,
/// <summary>
/// The game is currently loading.
/// </summary>
Loading,
/// <summary>
/// The game is fully loaded and ready to start sessions
/// </summary>
Loaded,
/// <summary>
/// The game is beginning the unload sequence
/// </summary>
Unloading,
/// <summary>
/// The game has been shutdown and is no longer active
/// </summary>
Unloaded
}
/// <summary>
/// Callback raised when a game's state changes
/// </summary>
/// <param name="game">The game who had a state change</param>
/// <param name="newState">The game's new state</param>
public delegate void TorchGameStateChangedDel(MySandboxGame game, TorchGameState newState);
}

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="NLog" version="4.4.1" targetFramework="net461" /> <package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
<package id="NLog" version="4.4.12" targetFramework="net461" />
</packages> </packages>

View File

@@ -1,12 +1,17 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Torch Client")] [assembly: AssemblyTitle("Torch Client Tests")]
[assembly: AssemblyDescription("")] [assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")] [assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Torch")] [assembly: AssemblyProduct("Torch")]
[assembly: AssemblyCopyright("Copyright © Torch API 2017")] [assembly: AssemblyCopyright("Copyright © Torch API 2017")]
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")] [assembly: AssemblyCulture("")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

View File

@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{632E78C0-0DAC-4B71-B411-2F1B333CC310}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Torch.Client.Tests</RootNamespace>
<AssemblyName>Torch.Client.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<NoWarn>1591,0649</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>$(SolutionDir)\bin-test\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>$(SolutionDir)\bin-test\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(SolutionDir)\bin-test\x64\Release\Torch.Client.Tests.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\Versioning\AssemblyVersion.cs">
<Link>Properties\AssemblyVersion.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TorchClientReflectionTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Torch.API\Torch.API.csproj">
<Project>{fba5d932-6254-4a1e-baf4-e229fa94e3c2}</Project>
<Name>Torch.API</Name>
</ProjectReference>
<ProjectReference Include="..\Torch.Client\Torch.Client.csproj">
<Project>{e36df745-260b-4956-a2e8-09f08b2e7161}</Project>
<Name>Torch.Client</Name>
</ProjectReference>
<ProjectReference Include="..\Torch.Tests\Torch.Tests.csproj">
<Project>{c3c8b671-6ad1-44aa-a8da-e0c0dc0fedf5}</Project>
<Name>Torch.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Torch\Torch.csproj">
<Project>{7e01635c-3b67-472e-bcd6-c5539564f214}</Project>
<Name>Torch</Name>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\TransformOnBuild.targets" />
</Project>

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using Torch.Client;
using Torch.Tests;
using Torch.Utils;
using Xunit;
namespace Torch.Client.Tests
{
public class TorchClientReflectionTest
{
static TorchClientReflectionTest()
{
TestUtils.Init();
}
private static ReflectionTestManager _manager;
private static ReflectionTestManager Manager()
{
if (_manager != null)
return _manager;
return _manager = new ReflectionTestManager().Init(typeof(TorchClient).Assembly);
}
public static IEnumerable<object[]> Getters => Manager().Getters;
public static IEnumerable<object[]> Setters => Manager().Setters;
public static IEnumerable<object[]> Invokers => Manager().Invokers;
public static IEnumerable<object[]> MemberInfo => Manager().MemberInfo;
public static IEnumerable<object[]> Events => Manager().Events;
#region Binding
[Theory]
[MemberData(nameof(Getters))]
public void TestBindingGetter(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
Assert.NotNull(field.Field.GetValue(null));
}
[Theory]
[MemberData(nameof(Setters))]
public void TestBindingSetter(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
Assert.NotNull(field.Field.GetValue(null));
}
[Theory]
[MemberData(nameof(Invokers))]
public void TestBindingInvoker(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
Assert.NotNull(field.Field.GetValue(null));
}
[Theory]
[MemberData(nameof(MemberInfo))]
public void TestBindingMemberInfo(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
Assert.NotNull(field.Field.GetValue(null));
}
[Theory]
[MemberData(nameof(Events))]
public void TestBindingEvents(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
((Func<ReflectedEventReplacer>)field.Field.GetValue(null)).Invoke();
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
<package id="NLog" version="4.4.12" targetFramework="net461" />
<package id="xunit" version="2.2.0" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
<package id="xunit.assert" version="2.2.0" targetFramework="net461" />
<package id="xunit.core" version="2.2.0" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net461" />
<package id="xunit.runner.console" version="2.2.0" targetFramework="net461" developmentDependency="true" />
</packages>

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Engine.Multiplayer;
using Torch.API;
using Torch.API.Managers;
using Torch.Managers;
namespace Torch.Client.Manager
{
public class MultiplayerManagerClient : MultiplayerManagerBase, IMultiplayerManagerClient
{
/// <inheritdoc />
public MultiplayerManagerClient(ITorchBase torch) : base(torch) { }
/// <inheritdoc />
public override void Attach()
{
base.Attach();
MyMultiplayer.Static.ClientJoined += RaiseClientJoined;
}
/// <inheritdoc />
public override void Detach()
{
MyMultiplayer.Static.ClientJoined -= RaiseClientJoined;
base.Detach();
}
}
}

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Engine.Multiplayer;
using Torch.API;
using Torch.API.Managers;
using Torch.Managers;
namespace Torch.Client.Manager
{
public class MultiplayerManagerLobby : MultiplayerManagerBase, IMultiplayerManagerServer
{
/// <inheritdoc />
public IReadOnlyList<ulong> BannedPlayers => new List<ulong>();
/// <inheritdoc />
public MultiplayerManagerLobby(ITorchBase torch) : base(torch) { }
/// <inheritdoc />
public void KickPlayer(ulong steamId) => Torch.Invoke(() => MyMultiplayer.Static.KickClient(steamId));
/// <inheritdoc />
public void BanPlayer(ulong steamId, bool banned = true) => Torch.Invoke(() => MyMultiplayer.Static.BanClient(steamId, banned));
/// <inheritdoc />
public bool IsBanned(ulong steamId) => false;
/// <inheritdoc />
public event Action<ulong> PlayerKicked
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc />
public event Action<ulong, bool> PlayerBanned
{
add => throw new NotImplementedException();
remove => throw new NotImplementedException();
}
/// <inheritdoc/>
public override void Attach()
{
base.Attach();
MyMultiplayer.Static.ClientJoined += RaiseClientJoined;
}
/// <inheritdoc/>
public override void Detach()
{
MyMultiplayer.Static.ClientJoined -= RaiseClientJoined;
base.Detach();
}
}
}

View File

@@ -1,17 +1,180 @@
using System; using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Windows; using System.Windows;
using System.Windows.Forms;
using NLog; using NLog;
using Torch.Utils;
using MessageBox = System.Windows.MessageBox;
namespace Torch.Client namespace Torch.Client
{ {
public static class Program public static class Program
{ {
public const string SpaceEngineersBinaries = "Bin64";
private static string _spaceEngInstallAlias = null;
public static string SpaceEngineersInstallAlias
{
get
{
// ReSharper disable once ConvertIfStatementToNullCoalescingExpression
if (_spaceEngInstallAlias == null)
{
// ReSharper disable once AssignNullToNotNullAttribute
_spaceEngInstallAlias = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location),
"SpaceEngineersAlias");
}
return _spaceEngInstallAlias;
}
}
private const string _steamSpaceEngineersDirectory = @"steamapps\common\SpaceEngineers\";
private const string _spaceEngineersVerifyFile = SpaceEngineersBinaries + @"\SpaceEngineers.exe";
public const string ConfigName = "Torch.cfg";
private static Logger _log = LogManager.GetLogger("Torch"); private static Logger _log = LogManager.GetLogger("Torch");
#if DEBUG
[DllImport("kernel32.dll")]
private static extern void AllocConsole();
[DllImport("kernel32.dll")]
private static extern void FreeConsole();
#endif
public static void Main(string[] args) public static void Main(string[] args)
{ {
#if DEBUG
try
{
AllocConsole();
#endif
if (!TorchLauncher.IsTorchWrapped())
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
// Early config: Resolve SE install directory.
if (!File.Exists(Path.Combine(SpaceEngineersInstallAlias, _spaceEngineersVerifyFile)))
SetupSpaceEngInstallAlias();
TorchLauncher.Launch(Assembly.GetEntryAssembly().FullName, args,
Path.Combine(SpaceEngineersInstallAlias, SpaceEngineersBinaries));
return;
}
RunClient();
#if DEBUG
}
finally
{
FreeConsole();
}
#endif
}
private static void SetupSpaceEngInstallAlias()
{
string spaceEngineersDirectory = null;
// TODO look at Steam/config/Config.VDF? Has alternate directories.
var steamDir =
Microsoft.Win32.Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\Valve\\Steam", "SteamPath",
null) as string;
if (steamDir != null)
{
spaceEngineersDirectory = Path.Combine(steamDir, _steamSpaceEngineersDirectory);
// ReSharper disable once ConvertIfStatementToConditionalTernaryExpression
if (File.Exists(Path.Combine(spaceEngineersDirectory, _spaceEngineersVerifyFile)))
_log.Debug("Found Space Engineers in {0}", spaceEngineersDirectory);
else
{
_log.Debug("Couldn't find Space Engineers in {0}", spaceEngineersDirectory);
spaceEngineersDirectory = null;
}
}
if (spaceEngineersDirectory == null)
{
var dialog = new System.Windows.Forms.FolderBrowserDialog
{
Description = "Please select the SpaceEngineers installation folder"
};
do
{
if (dialog.ShowDialog() != DialogResult.OK)
{
var ex = new FileNotFoundException(
"Unable to find the Space Engineers install directory, aborting");
_log.Fatal(ex);
LogManager.Flush();
throw ex;
}
spaceEngineersDirectory = dialog.SelectedPath;
if (File.Exists(Path.Combine(spaceEngineersDirectory, _spaceEngineersVerifyFile)))
break;
if (MessageBox.Show(
$"Unable to find {0} in {1}. Are you sure it's the Space Engineers install directory?",
"Invalid Space Engineers Directory", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
break;
} while (true); // Repeat until they confirm.
}
if (!JunctionLink(SpaceEngineersInstallAlias, spaceEngineersDirectory))
{
var ex = new IOException(
$"Failed to create junction link {SpaceEngineersInstallAlias} => {spaceEngineersDirectory}. Aborting.");
_log.Fatal(ex);
LogManager.Flush();
throw ex;
}
string junctionVerify = Path.Combine(SpaceEngineersInstallAlias, _spaceEngineersVerifyFile);
if (!File.Exists(junctionVerify))
{
var ex = new FileNotFoundException(
$"Junction link is not working. File {junctionVerify} does not exist");
_log.Fatal(ex);
LogManager.Flush();
throw ex;
}
}
private static bool JunctionLink(string linkName, string targetDir)
{
var junctionLinkProc = new ProcessStartInfo("cmd.exe", $"/c mklink /J \"{linkName}\" \"{targetDir}\"")
{
WorkingDirectory = Directory.GetCurrentDirectory(),
UseShellExecute = false,
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.ASCII
};
Process cmd = Process.Start(junctionLinkProc);
// ReSharper disable once PossibleNullReferenceException
while (!cmd.HasExited)
{
string line = cmd.StandardOutput.ReadLine();
if (!string.IsNullOrWhiteSpace(line))
_log.Info(line);
Thread.Sleep(100);
}
if (cmd.ExitCode != 0)
_log.Error("Unable to create junction link {0} => {1}", linkName, targetDir);
return cmd.ExitCode == 0;
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception) e.ExceptionObject;
_log.Error(ex);
LogManager.Flush();
MessageBox.Show(ex.StackTrace, ex.Message);
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void RunClient()
{
var client = new TorchClient(); var client = new TorchClient();
try try
@@ -27,11 +190,5 @@ namespace Torch.Client
client.Start(); client.Start();
} }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception)e.ExceptionObject;
MessageBox.Show(ex.StackTrace, ex.Message);
}
} }
} }

View File

@@ -1,4 +1,17 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyVersion("1.0.207.7")] [assembly: AssemblyTitle("Torch Client")]
[assembly: AssemblyFileVersion("1.0.207.7")] [assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Torch")]
[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

View File

@@ -1,16 +0,0 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
using System.Reflection;
<# var dt = DateTime.Now;
int major = 1;
int minor = 0;
int build = dt.DayOfYear;
int rev = (int)dt.TimeOfDay.TotalMinutes / 2;
#>
[assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]
[assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]

View File

@@ -2,8 +2,6 @@
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{E36DF745-260B-4956-A2E8-09F08B2E7161}</ProjectGuid> <ProjectGuid>{E36DF745-260B-4956-A2E8-09F08B2E7161}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
@@ -15,10 +13,12 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath> <OutputPath>$(SolutionDir)\bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
@@ -27,7 +27,7 @@
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath> <OutputPath>$(SolutionDir)\bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
@@ -35,19 +35,20 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
<DocumentationFile>bin\x64\Release\Torch.Client.xml</DocumentationFile> <DocumentationFile>$(SolutionDir)\bin\x64\Release\Torch.Client.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>torchicon.ico</ApplicationIcon> <ApplicationIcon>torchicon.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.1\lib\net45\NLog.dll</HintPath> <HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
<Private>True</Private> <Private>True</Private>
</Reference> </Reference>
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\GameBinaries\Sandbox.Common.dll</HintPath> <HintPath>..\GameBinaries\Sandbox.Common.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="Sandbox.Game"> <Reference Include="Sandbox.Game">
<HintPath>..\GameBinaries\Sandbox.Game.dll</HintPath> <HintPath>..\GameBinaries\Sandbox.Game.dll</HintPath>
@@ -64,6 +65,7 @@
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@@ -81,6 +83,10 @@
<HintPath>..\GameBinaries\VRage.Game.dll</HintPath> <HintPath>..\GameBinaries\VRage.Game.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="VRage.Game.XmlSerializers">
<HintPath>..\GameBinaries\VRage.Game.XmlSerializers.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="VRage.Input, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="VRage.Input, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\GameBinaries\VRage.Input.dll</HintPath> <HintPath>..\GameBinaries\VRage.Input.dll</HintPath>
@@ -103,20 +109,24 @@
<HintPath>..\GameBinaries\VRage.Render11.dll</HintPath> <HintPath>..\GameBinaries\VRage.Render11.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="VRage.Steam">
<HintPath>..\GameBinaries\VRage.Steam.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="..\Versioning\AssemblyVersion.cs">
<DependentUpon>AssemblyInfo.tt</DependentUpon> <Link>Properties\AssemblyVersion.cs</Link>
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo1.cs" /> <Compile Include="Manager\MultiplayerManagerClient.cs" />
<Compile Include="Manager\MultiplayerManagerLobby.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TorchClient.cs" /> <Compile Include="TorchClient.cs" />
<Compile Include="TorchClientConfig.cs" />
<Compile Include="TorchConsoleScreen.cs" /> <Compile Include="TorchConsoleScreen.cs" />
<Compile Include="TorchMainMenuScreen.cs" />
<Compile Include="TorchSettingsScreen.cs" /> <Compile Include="TorchSettingsScreen.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">
@@ -129,6 +139,9 @@
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<Compile Include="UI\TorchMainMenuScreen.cs" />
<Compile Include="UI\TorchNavScreen.cs" />
<Compile Include="UI\TorchSettingsScreen.cs" />
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>
@@ -144,35 +157,25 @@
<ProjectReference Include="..\Torch.API\Torch.API.csproj"> <ProjectReference Include="..\Torch.API\Torch.API.csproj">
<Project>{fba5d932-6254-4a1e-baf4-e229fa94e3c2}</Project> <Project>{fba5d932-6254-4a1e-baf4-e229fa94e3c2}</Project>
<Name>Torch.API</Name> <Name>Torch.API</Name>
<Private>True</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Torch\Torch.csproj"> <ProjectReference Include="..\Torch\Torch.csproj">
<Project>{7E01635C-3B67-472E-BCD6-C5539564F214}</Project> <Project>{7E01635C-3B67-472E-BCD6-C5539564F214}</Project>
<Name>Torch</Name> <Name>Torch</Name>
<Private>True</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="torchicon.ico" /> <Resource Include="torchicon.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Include="Properties\AssemblyInfo.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>AssemblyInfo.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\TransformOnBuild.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>copy "$(SolutionDir)NLog.config" "$(TargetDir)"</PostBuildEvent> <PostBuildEvent>copy "$(SolutionDir)NLog.config" "$(TargetDir)"
</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project> </Project>

View File

@@ -1,71 +1,56 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows; using System.Windows;
using Sandbox; using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Engine.Networking;
using Sandbox.Engine.Platform; using Sandbox.Engine.Platform;
using Sandbox.Engine.Utils;
using Sandbox.Game; using Sandbox.Game;
using Sandbox.ModAPI;
using SpaceEngineers.Game; using SpaceEngineers.Game;
using VRage.Steam;
using Torch.API; using Torch.API;
using Torch.API.Managers;
using Torch.API.Session;
using Torch.Client.Manager;
using Torch.Client.UI;
using Torch.Session;
using VRage;
using VRage.FileSystem; using VRage.FileSystem;
using VRage.GameServices;
using VRageRender; using VRageRender;
using VRageRender.ExternalApp;
namespace Torch.Client namespace Torch.Client
{ {
public class TorchClient : TorchBase, ITorchClient public class TorchClient : TorchBase, ITorchClient
{ {
private MyCommonProgramStartup _startup; protected override uint SteamAppId => 244850;
private IMyRender _renderer; protected override string SteamAppName => "SpaceEngineers";
private const uint APP_ID = 244850;
private VRageGameServices _services; public TorchClient()
{
Config = new TorchClientConfig();
var sessionManager = Managers.GetManager<ITorchSessionManager>();
sessionManager.AddFactory((x) => MyMultiplayer.Static is MyMultiplayerLobby
? new MultiplayerManagerLobby(this)
: null);
sessionManager.AddFactory((x) => MyMultiplayer.Static is MyMultiplayerClientBase
? new MultiplayerManagerClient(this)
: null);
}
public override void Init() public override void Init()
{ {
Directory.SetCurrentDirectory(Program.SpaceEngineersInstallAlias);
MyFileSystem.ExePath = Path.Combine(Program.SpaceEngineersInstallAlias, Program.SpaceEngineersBinaries);
Log.Info("Initializing Torch Client"); Log.Info("Initializing Torch Client");
Config.InstancePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
SteamAppName);
base.Init(); base.Init();
if (!File.Exists("steam_appid.txt"))
{
Directory.SetCurrentDirectory(Path.GetDirectoryName(typeof(VRage.FastResourceLock).Assembly.Location) + "\\..");
}
SpaceEngineersGame.SetupBasicGameInfo();
_startup = new MyCommonProgramStartup(RunArgs);
if (_startup.PerformReporting())
return;
_startup.PerformAutoconnect();
if (!_startup.CheckSingleInstance())
return;
var appDataPath = _startup.GetAppDataPath();
MyInitializer.InvokeBeforeRun(APP_ID, MyPerGameSettings.BasicGameInfo.ApplicationName, appDataPath);
MyInitializer.InitCheckSum();
if (!_startup.Check64Bit())
return;
_startup.DetectSharpDxLeaksBeforeRun();
using (var mySteamService = new SteamService(Game.IsDedicated, APP_ID))
{
_renderer = null;
SpaceEngineersGame.SetupPerGameSettings();
OverrideMenus(); OverrideMenus();
SetRenderWindowTitle($"Space Engineers v{GameVersion} with Torch v{TorchVersion}");
InitializeRender();
_services = new VRageGameServices(mySteamService);
if (!Game.IsDedicated)
MyFileSystem.InitUserSpecific(mySteamService.UserId.ToString());
}
_startup.DetectSharpDxLeaksAfterRun();
MyInitializer.InvokeAfterRun();
} }
private void OverrideMenus() private void OverrideMenus()
@@ -83,60 +68,25 @@ namespace Torch.Client
MyPerGameSettings.GUI.MainMenu = typeof(TorchMainMenuScreen); MyPerGameSettings.GUI.MainMenu = typeof(TorchMainMenuScreen);
} }
public override void Start() private void SetRenderWindowTitle(string title)
{ {
using (var spaceEngineersGame = new SpaceEngineersGame(_services, RunArgs)) MyRenderThread renderThread = MySandboxGame.Static?.GameRenderComponent?.RenderThread;
{ if (renderThread == null)
Log.Info("Starting client"); return;
spaceEngineersGame.OnGameLoaded += SpaceEngineersGame_OnGameLoaded; FieldInfo renderWindowField = typeof(MyRenderThread).GetField("m_renderWindow",
spaceEngineersGame.Run(); BindingFlags.Instance | BindingFlags.NonPublic);
} if (renderWindowField == null)
return;
var window =
renderWindowField.GetValue(MySandboxGame.Static.GameRenderComponent.RenderThread) as
System.Windows.Forms.Form;
if (window != null)
renderThread.Invoke(() => { window.Text = title; });
} }
private void SpaceEngineersGame_OnGameLoaded(object sender, EventArgs e) public override void Restart()
{ {
} throw new NotImplementedException();
public override void Stop()
{
MySandboxGame.ExitThreadSafe();
}
private void InitializeRender()
{
try
{
if (Game.IsDedicated)
{
_renderer = new MyNullRender();
}
else
{
var graphicsRenderer = MySandboxGame.Config.GraphicsRenderer;
if (graphicsRenderer == MySandboxGame.DirectX11RendererKey)
{
_renderer = new MyDX11Render();
if (!_renderer.IsSupported)
{
MySandboxGame.Log.WriteLine("DirectX 11 renderer not supported. No renderer to revert back to.");
_renderer = null;
}
}
if (_renderer == null)
throw new MyRenderException("The current version of the game requires a Dx11 card. \\n For more information please see : http://blog.marekrosa.org/2016/02/space-engineers-news-full-source-code_26.html", MyRenderExceptionEnum.GpuNotSupported);
MySandboxGame.Config.GraphicsRenderer = graphicsRenderer;
}
MyRenderProxy.Initialize(_renderer);
MyRenderProxy.GetRenderProfiler().SetAutocommit(false);
MyRenderProxy.GetRenderProfiler().InitMemoryHack("MainEntryPoint");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Render Initialization Failed");
Environment.Exit(-1);
}
} }
} }
} }

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Torch.Client
{
public class TorchClientConfig : ITorchConfig
{
// How do we want to handle client side config? It's radically different than the server.
public bool GetPluginUpdates { get; set; } = false;
public bool GetTorchUpdates { get; set; } = false;
public string InstanceName { get; set; } = "TorchClient";
public string InstancePath { get; set; }
public bool NoUpdate { get; set; } = true;
public List<string> Plugins { get; set; }
public bool ShouldUpdatePlugins { get; } = false;
public bool ShouldUpdateTorch { get; } = false;
public int TickTimeout { get; set; }
public bool Autostart { get; set; } = false;
public bool ForceUpdate { get; set; } = false;
public bool NoGui { get; set; } = false;
public bool RestartOnCrash { get; set; } = false;
public string WaitForPID { get; set; } = null;
public bool Save(string path = null)
{
return true;
}
}
}

View File

@@ -1,35 +0,0 @@
#pragma warning disable 618
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Graphics;
using Sandbox.Graphics.GUI;
using Sandbox.Gui;
using SpaceEngineers.Game.GUI;
using VRage.Game;
using VRage.Utils;
using VRageMath;
namespace Torch.Client
{
public class TorchMainMenuScreen : MyGuiScreenMainMenu
{
/// <inheritdoc />
public override void RecreateControls(bool constructor)
{
base.RecreateControls(constructor);
var buttonSize = MyGuiControlButton.GetVisualStyle(MyGuiControlButtonStyleEnum.Default).NormalTexture.MinSizeGui;
Vector2 leftButtonPositionOrigin = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM) + new Vector2(buttonSize.X / 2f, 0f);
var btn = MakeButton(leftButtonPositionOrigin - 9 * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyStringId.GetOrCompute("Torch"), TorchButtonClicked);
Controls.Add(btn);
}
private void TorchButtonClicked(MyGuiControlButton obj)
{
MyGuiSandbox.AddScreen(new TorchSettingsScreen());
}
}
}

View File

@@ -0,0 +1,56 @@
#pragma warning disable 618
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Engine.Networking;
using Sandbox.Engine.Utils;
using Sandbox.Game;
using Sandbox.Game.Gui;
using Sandbox.Graphics;
using Sandbox.Graphics.GUI;
using Sandbox.Gui;
using SpaceEngineers.Game.GUI;
using Torch.Utils;
using VRage.Game;
using VRage.Utils;
using VRageMath;
namespace Torch.Client.UI
{
public class TorchMainMenuScreen : MyGuiScreenMainMenu
{
#pragma warning disable 169
[ReflectedGetter(Name = "m_elementGroup")]
private static Func<MyGuiScreenMainMenu, MyGuiControlElementGroup> _elementsGroup;
#pragma warning restore 169
public TorchMainMenuScreen() : this(false)
{
}
public TorchMainMenuScreen(bool pauseGame)
: base(pauseGame)
{
}
/// <inheritdoc />
public override void RecreateControls(bool constructor)
{
base.RecreateControls(constructor);
Vector2 minSizeGui = MyGuiControlButton.GetVisualStyle(MyGuiControlButtonStyleEnum.Default).NormalTexture.MinSizeGui;
Vector2 value = MyGuiManager.ComputeFullscreenGuiCoordinate(MyGuiDrawAlignEnum.HORISONTAL_LEFT_AND_VERTICAL_BOTTOM, 54, 54) + new Vector2(minSizeGui.X / 2f, 0f) + new Vector2(15f, 0f) / MyGuiConstants.GUI_OPTIMAL_SIZE;
MyGuiControlButton myGuiControlButton = MakeButton(value - 9 * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA,
MyStringId.GetOrCompute("Torch"), TorchButtonClicked, MyCommonTexts.ToolTipExitToWindows);
Controls.Add(myGuiControlButton);
_elementsGroup.Invoke(this).Add(myGuiControlButton);
}
private void TorchButtonClicked(MyGuiControlButton obj)
{
MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen<TorchNavScreen>());
}
}
}

View File

@@ -0,0 +1,49 @@
using Sandbox;
using Sandbox.Game.Gui;
using Sandbox.Graphics.GUI;
using VRage;
using VRage.Game;
using VRage.Utils;
using VRageMath;
namespace Torch.Client.UI
{
public class TorchNavScreen : MyGuiScreenBase
{
private MyGuiControlElementGroup _elementGroup;
public TorchNavScreen() : base(new Vector2(0.5f, 0.5f), MyGuiConstants.SCREEN_BACKGROUND_COLOR, new Vector2(0.35875f, 0.558333337f))
{
EnabledBackgroundFade = true;
RecreateControls(true);
}
public override void RecreateControls(bool constructor)
{
base.RecreateControls(constructor);
_elementGroup = new MyGuiControlElementGroup();
_elementGroup.HighlightChanged += ElementGroupHighlightChanged;
AddCaption(MyCommonTexts.ScreenCaptionOptions, null, null);
var value = new Vector2(0f, -m_size.Value.Y / 2f + 0.146f);
var num = 0;
var myGuiControlButton = new MyGuiControlButton(value + num++ * MyGuiConstants.MENU_BUTTONS_POSITION_DELTA, MyGuiControlButtonStyleEnum.Default, null, null, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, null, MyTexts.Get(MyCommonTexts.ScreenOptionsButtonGame), 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER, MyGuiControlHighlightType.WHEN_ACTIVE, delegate(MyGuiControlButton sender)
{
MyGuiSandbox.AddScreen(MyGuiSandbox.CreateScreen<TorchSettingsScreen>());
}, GuiSounds.MouseClick, 1f, null);
Controls.Add(myGuiControlButton);
_elementGroup.Add(myGuiControlButton);
CloseButtonEnabled = true;
}
private void ElementGroupHighlightChanged(MyGuiControlElementGroup obj)
{
foreach (MyGuiControlBase current in _elementGroup)
if (current.HasFocus && obj.SelectedElement != current)
FocusedControl = obj.SelectedElement;
}
public override string GetFriendlyName() => "Torch";
public void OnBackClick(MyGuiControlButton sender) => CloseScreen();
}
}

View File

@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sandbox.Graphics.GUI;
using VRageMath;
namespace Torch.Client.UI
{
public class TorchSettingsScreen : MyGuiScreenBase
{
public TorchSettingsScreen() : base(new Vector2(0.5f, 0.5f), MyGuiConstants.SCREEN_BACKGROUND_COLOR,
new Vector2(0.35875f, 0.558333337f))
{
EnabledBackgroundFade = true;
RecreateControls(true);
}
/// <inheritdoc />
public override string GetFriendlyName() => "Torch Settings";
public void OnBackClick(MyGuiControlButton sender) => CloseScreen();
}
}

View File

@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="NLog" version="4.4.1" targetFramework="net461" /> <package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
<package id="NLog" version="4.4.12" targetFramework="net461" />
</packages> </packages>

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProtoBuf;
using Sandbox.ModAPI;
namespace Torch.Mod.Messages
{
/// Dialogs are structured as follows
///
/// _____________________________________
/// | Title |
/// --------------------------------------
/// | Prefix Subtitle |
/// --------------------------------------
/// | ________________________________ |
/// | | Content | |
/// | --------------------------------- |
/// | ____________ |
/// | | ButtonText | |
/// | -------------- |
/// --------------------------------------
///
/// Button has a callback on click option,
/// but can't serialize that, so ¯\_(ツ)_/¯
[ProtoContract]
public class DialogMessage : MessageBase
{
[ProtoMember(201)]
public string Title;
[ProtoMember(202)]
public string Subtitle;
[ProtoMember(203)]
public string Prefix;
[ProtoMember(204)]
public string Content;
[ProtoMember(205)]
public string ButtonText;
public DialogMessage()
{ }
public DialogMessage(string title, string subtitle, string content)
{
Title = title;
Subtitle = subtitle;
Content = content;
Prefix = String.Empty;
}
public DialogMessage(string title = null, string prefix = null, string subtitle = null, string content = null, string buttonText = null)
{
Title = title;
Subtitle = subtitle;
Prefix = prefix ?? String.Empty;
Content = content;
ButtonText = buttonText;
}
public override void ProcessClient()
{
MyAPIGateway.Utilities.ShowMissionScreen(Title, Prefix, Subtitle, Content, null, ButtonText);
}
public override void ProcessServer()
{
throw new Exception();
}
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Torch.Mod.Messages
{
/// <summary>
/// shim to store incoming message data
/// </summary>
internal class IncomingMessage : MessageBase
{
public IncomingMessage()
{
}
public override void ProcessClient()
{
throw new Exception();
}
public override void ProcessServer()
{
throw new Exception();
}
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProtoBuf;
namespace Torch.Mod.Messages
{
#region Includes
[ProtoInclude(1, typeof(DialogMessage))]
[ProtoInclude(2, typeof(NotificationMessage))]
[ProtoInclude(3, typeof(VoxelResetMessage))]
#endregion
[ProtoContract]
public abstract class MessageBase
{
[ProtoMember(101)]
public ulong SenderId;
public abstract void ProcessClient();
public abstract void ProcessServer();
//members below not serialized, they're just metadata about the intended target(s) of this message
internal MessageTarget TargetType;
internal ulong Target;
internal ulong[] Ignore;
internal byte[] CompressedData;
}
public enum MessageTarget
{
/// <summary>
/// Send to Target
/// </summary>
Single,
/// <summary>
/// Send to Server
/// </summary>
Server,
/// <summary>
/// Send to all Clients (only valid from server)
/// </summary>
AllClients,
/// <summary>
/// Send to all except those steam ID listed in Ignore
/// </summary>
AllExcept,
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Text;
using ProtoBuf;
using Sandbox.ModAPI;
namespace Torch.Mod.Messages
{
[ProtoContract]
public class NotificationMessage : MessageBase
{
[ProtoMember(201)]
public string Message;
[ProtoMember(202)]
public string Font;
[ProtoMember(203)]
public int DisappearTimeMs;
public NotificationMessage()
{ }
public NotificationMessage(string message, int disappearTimeMs, string font)
{
Message = message;
DisappearTimeMs = disappearTimeMs;
Font = font;
}
public override void ProcessClient()
{
MyAPIGateway.Utilities.ShowNotification(Message, DisappearTimeMs, Font);
}
public override void ProcessServer()
{
throw new Exception();
}
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
using ProtoBuf;
using Sandbox.ModAPI;
using VRage.ModAPI;
using VRage.Voxels;
namespace Torch.Mod.Messages
{
[ProtoContract]
public class VoxelResetMessage : MessageBase
{
[ProtoMember(201)]
public long[] EntityId;
public VoxelResetMessage()
{ }
public VoxelResetMessage(long[] entityId)
{
EntityId = entityId;
}
public override void ProcessClient()
{
//MyAPIGateway.Parallel.ForEach(EntityId, id =>
foreach (var id in EntityId)
{
IMyEntity e;
if (!MyAPIGateway.Entities.TryGetEntityById(id, out e))
continue;
var v = e as IMyVoxelBase;
v?.Storage.Reset(MyStorageDataTypeFlags.All);
}
}
public override void ProcessServer()
{
throw new Exception();
}
}
}

View File

@@ -0,0 +1,189 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Sandbox.ModAPI;
using Torch.Mod.Messages;
using VRage;
using VRage.Collections;
using VRage.Game.ModAPI;
using VRage.Utils;
using Task = ParallelTasks.Task;
namespace Torch.Mod
{
public static class ModCommunication
{
public const ushort NET_ID = 4352;
private static bool _closing = false;
private static BlockingCollection<MessageBase> _processing;
private static MyConcurrentPool<IncomingMessage> _messagePool;
private static List<IMyPlayer> _playerCache;
public static void Register()
{
MyLog.Default.WriteLineAndConsole("TORCH MOD: Registering mod communication.");
_processing = new BlockingCollection<MessageBase>(new ConcurrentQueue<MessageBase>());
_playerCache = new List<IMyPlayer>();
_messagePool = new MyConcurrentPool<IncomingMessage>(8);
MyAPIGateway.Multiplayer.RegisterMessageHandler(NET_ID, MessageHandler);
//background thread to handle de/compression and processing
_closing = false;
MyAPIGateway.Parallel.StartBackground(DoProcessing);
MyLog.Default.WriteLineAndConsole("TORCH MOD: Mod communication registered successfully.");
}
public static void Unregister()
{
MyLog.Default.WriteLineAndConsole("TORCH MOD: Unregistering mod communication.");
MyAPIGateway.Multiplayer?.UnregisterMessageHandler(NET_ID, MessageHandler);
_processing?.CompleteAdding();
_closing = true;
//_task.Wait();
}
private static void MessageHandler(byte[] bytes)
{
var m = _messagePool.Get();
m.CompressedData = bytes;
_processing.Add(m);
}
public static void DoProcessing()
{
while (!_closing)
{
try
{
var m = _processing.Take();
MyLog.Default.WriteLineAndConsole($"Processing message: {m.GetType().Name}");
if (m is IncomingMessage)
{
MessageBase i;
try
{
var o = MyCompression.Decompress(m.CompressedData);
m.CompressedData = null;
_messagePool.Return((IncomingMessage)m);
i = MyAPIGateway.Utilities.SerializeFromBinary<MessageBase>(o);
}
catch (Exception ex)
{
MyLog.Default.WriteLineAndConsole($"TORCH MOD: Failed to deserialize message! {ex}");
continue;
}
if (MyAPIGateway.Multiplayer.IsServer)
i.ProcessServer();
else
i.ProcessClient();
}
else
{
var b = MyAPIGateway.Utilities.SerializeToBinary(m);
m.CompressedData = MyCompression.Compress(b);
MyAPIGateway.Utilities.InvokeOnGameThread(() =>
{
switch (m.TargetType)
{
case MessageTarget.Single:
MyAPIGateway.Multiplayer.SendMessageTo(NET_ID, m.CompressedData, m.Target);
break;
case MessageTarget.Server:
MyAPIGateway.Multiplayer.SendMessageToServer(NET_ID, m.CompressedData);
break;
case MessageTarget.AllClients:
MyAPIGateway.Players.GetPlayers(_playerCache);
foreach (var p in _playerCache)
{
if (p.SteamUserId == MyAPIGateway.Multiplayer.MyId)
continue;
MyAPIGateway.Multiplayer.SendMessageTo(NET_ID, m.CompressedData, p.SteamUserId);
}
break;
case MessageTarget.AllExcept:
MyAPIGateway.Players.GetPlayers(_playerCache);
foreach (var p in _playerCache)
{
if (p.SteamUserId == MyAPIGateway.Multiplayer.MyId || m.Ignore.Contains(p.SteamUserId))
continue;
MyAPIGateway.Multiplayer.SendMessageTo(NET_ID, m.CompressedData, p.SteamUserId);
}
break;
default:
throw new Exception();
}
_playerCache.Clear();
});
}
}
catch (Exception ex)
{
MyLog.Default.WriteLineAndConsole($"TORCH MOD: Exception occurred in communication thread! {ex}");
}
}
MyLog.Default.WriteLineAndConsole("TORCH MOD: COMMUNICATION THREAD: EXIT SIGNAL RECEIVED!");
//exit signal received. Clean everything and GTFO
_processing?.Dispose();
_processing = null;
_messagePool?.Clean();
_messagePool = null;
_playerCache = null;
}
public static void SendMessageTo(MessageBase message, ulong target)
{
if (!MyAPIGateway.Multiplayer.IsServer)
throw new Exception("Only server can send targeted messages");
if (_closing)
return;
message.Target = target;
message.TargetType = MessageTarget.Single;
_processing.Add(message);
}
public static void SendMessageToClients(MessageBase message)
{
if (!MyAPIGateway.Multiplayer.IsServer)
throw new Exception("Only server can send targeted messages");
if (_closing)
return;
message.TargetType = MessageTarget.AllClients;
_processing.Add(message);
}
public static void SendMessageExcept(MessageBase message, params ulong[] ignoredUsers)
{
if (!MyAPIGateway.Multiplayer.IsServer)
throw new Exception("Only server can send targeted messages");
if (_closing)
return;
message.TargetType = MessageTarget.AllExcept;
message.Ignore = ignoredUsers;
_processing.Add(message);
}
public static void SendMessageToServer(MessageBase message)
{
if (_closing)
return;
message.TargetType = MessageTarget.Server;
_processing.Add(message);
}
}
}

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<HasSharedItems>true</HasSharedItems>
<SharedGUID>3ce4d2e9-b461-4f19-8233-f87e0dfddd74</SharedGUID>
</PropertyGroup>
<PropertyGroup Label="Configuration">
<Import_RootNamespace>Torch.Mod</Import_RootNamespace>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)Messages\IncomingMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\NotificationMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\DialogMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\MessageBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Messages\VoxelResetMessage.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ModCommunication.cs" />
<Compile Include="$(MSBuildThisFileDirectory)TorchModCore.cs" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Label="Globals">
<ProjectGuid>3ce4d2e9-b461-4f19-8233-f87e0dfddd74</ProjectGuid>
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.Default.props" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.Common.props" />
<PropertyGroup />
<Import Project="Torch.Mod.projitems" Label="Shared" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
</Project>

37
Torch.Mod/TorchModCore.cs Normal file
View File

@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VRage.Game.Components;
namespace Torch.Mod
{
[MySessionComponentDescriptor(MyUpdateOrder.AfterSimulation)]
public class TorchModCore : MySessionComponentBase
{
public const ulong MOD_ID = 1406994352;
private static bool _init;
public override void UpdateAfterSimulation()
{
if (_init)
return;
_init = true;
ModCommunication.Register();
}
protected override void UnloadData()
{
try
{
ModCommunication.Unregister();
}
catch
{
//session unloading, don't care
}
}
}
}

View File

@@ -0,0 +1,17 @@
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("Torch Server Tests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Torch")]
[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

View File

@@ -0,0 +1,102 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{9EFD1D91-2FA2-47ED-B537-D8BC3B0E543E}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Torch.Server.Tests</RootNamespace>
<AssemblyName>Torch.Server.Tests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<NoWarn>1591,0649</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>$(SolutionDir)\bin-test\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>$(SolutionDir)\bin-test\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DocumentationFile>$(SolutionDir)\bin-test\x64\Release\Torch.Server.Tests.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="VRage.Game, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\GameBinaries\VRage.Game.dll</HintPath>
</Reference>
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath>
</Reference>
<Reference Include="xunit.assert, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.assert.2.2.0\lib\netstandard1.1\xunit.assert.dll</HintPath>
</Reference>
<Reference Include="xunit.core, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.core.2.2.0\lib\netstandard1.1\xunit.core.dll</HintPath>
</Reference>
<Reference Include="xunit.execution.desktop, Version=2.2.0.3545, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
<HintPath>..\packages\xunit.extensibility.execution.2.2.0\lib\net452\xunit.execution.desktop.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="..\Versioning\AssemblyVersion.cs">
<Link>Properties\AssemblyVersion.cs</Link>
</Compile>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TorchServerReflectionTest.cs" />
<Compile Include="TorchServerSessionSettingsTest.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Torch.API\Torch.API.csproj">
<Project>{fba5d932-6254-4a1e-baf4-e229fa94e3c2}</Project>
<Name>Torch.API</Name>
</ProjectReference>
<ProjectReference Include="..\Torch.Server\Torch.Server.csproj">
<Project>{ca50886b-7b22-4cd8-93a0-c06f38d4f77d}</Project>
<Name>Torch.Server</Name>
</ProjectReference>
<ProjectReference Include="..\Torch.Tests\Torch.Tests.csproj">
<Project>{c3c8b671-6ad1-44aa-a8da-e0c0dc0fedf5}</Project>
<Name>Torch.Tests</Name>
</ProjectReference>
<ProjectReference Include="..\Torch\Torch.csproj">
<Project>{7e01635c-3b67-472e-bcd6-c5539564f214}</Project>
<Name>Torch</Name>
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\TransformOnBuild.targets" />
</Project>

View File

@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using Torch.Tests;
using Torch.Utils;
using Xunit;
namespace Torch.Server.Tests
{
#warning Disabled reflection tests because of seemingly random failures
public class TorchServerReflectionTest
{
static TorchServerReflectionTest()
{
TestUtils.Init();
}
private static ReflectionTestManager _manager;
private static ReflectionTestManager Manager()
{
if (_manager != null)
return _manager;
return _manager = new ReflectionTestManager().Init(typeof(TorchServer).Assembly);
}
public static IEnumerable<object[]> Getters => Manager().Getters;
public static IEnumerable<object[]> Setters => Manager().Setters;
public static IEnumerable<object[]> Invokers => Manager().Invokers;
public static IEnumerable<object[]> MemberInfo => Manager().MemberInfo;
public static IEnumerable<object[]> Events => Manager().Events;
#region Binding
//[Theory]
[MemberData(nameof(Getters))]
public void TestBindingGetter(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
Assert.NotNull(field.Field.GetValue(null));
}
//[Theory]
[MemberData(nameof(Setters))]
public void TestBindingSetter(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
Assert.NotNull(field.Field.GetValue(null));
}
//[Theory]
[MemberData(nameof(Invokers))]
public void TestBindingInvoker(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
Assert.NotNull(field.Field.GetValue(null));
}
//[Theory]
[MemberData(nameof(Events))]
public void TestBindingEvents(ReflectionTestManager.FieldRef field)
{
if (field.Field == null)
return;
Assert.True(ReflectedManager.Process(field.Field));
if (field.Field.IsStatic)
((Func<ReflectedEventReplacer>)field.Field.GetValue(null)).Invoke();
}
#endregion
}
}

View File

@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Torch.Server.ViewModels;
using VRage.Game;
using Xunit;
using System.ComponentModel.DataAnnotations;
namespace Torch.Server.Tests
{
public class TorchServerSessionSettingsTest
{
public static PropertyInfo[] ViewModelProperties = typeof(SessionSettingsViewModel).GetProperties(BindingFlags.Public | BindingFlags.Instance);
public static IEnumerable<object[]> ModelFields = typeof(MyObjectBuilder_SessionSettings).GetFields(BindingFlags.Public | BindingFlags.Instance).Select(x => new object[] { x });
[Theory]
[MemberData(nameof(ModelFields))]
public void MissingPropertyTest(FieldInfo modelField)
{
// Ignore fields that aren't applicable to SE
if (modelField.GetCustomAttribute<GameRelationAttribute>()?.RelatedTo == Game.MedievalEngineers)
return;
if (string.IsNullOrEmpty(modelField.GetCustomAttribute<DisplayAttribute>()?.Name))
return;
var match = ViewModelProperties.FirstOrDefault(p => p.Name.Equals(modelField.Name, StringComparison.InvariantCultureIgnoreCase));
Assert.NotNull(match);
}
}
}

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Mono.TextTransform" version="1.0.0" targetFramework="net461" />
<package id="NLog" version="4.4.12" targetFramework="net461" />
<package id="xunit" version="2.2.0" targetFramework="net461" />
<package id="xunit.abstractions" version="2.0.1" targetFramework="net461" />
<package id="xunit.assert" version="2.2.0" targetFramework="net461" />
<package id="xunit.core" version="2.2.0" targetFramework="net461" />
<package id="xunit.extensibility.core" version="2.2.0" targetFramework="net461" />
<package id="xunit.extensibility.execution" version="2.2.0" targetFramework="net461" />
<package id="xunit.runner.console" version="2.2.0" targetFramework="net461" developmentDependency="true" />
</packages>

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Torch.Commands;
namespace Torch.Server.Commands
{
[Category("whitelist")]
public class WhitelistCommands : CommandModule
{
private TorchConfig Config => (TorchConfig)Context.Torch.Config;
[Command("on", "Enables the whitelist.")]
public void On()
{
if (!Config.EnableWhitelist)
{
Config.EnableWhitelist = true;
Context.Respond("Whitelist enabled.");
Config.Save();
}
else
Context.Respond("Whitelist is already enabled.");
}
[Command("off", "Disables the whitelist")]
public void Off()
{
if (Config.EnableWhitelist)
{
Config.EnableWhitelist = false;
Context.Respond("Whitelist disabled.");
Config.Save();
}
else
Context.Respond("Whitelist is already disabled.");
}
[Command("add", "Add a Steam ID to the whitelist.")]
public void Add(ulong steamId)
{
if (Config.Whitelist.Add(steamId))
{
Context.Respond($"Added {steamId} to the whitelist.");
Config.Save();
}
else
Context.Respond($"{steamId} is already whitelisted.");
}
[Command("remove", "Remove a Steam ID from the whitelist.")]
public void Remove(ulong steamId)
{
if (Config.Whitelist.Remove(steamId))
{
Context.Respond($"Removed {steamId} from the whitelist.");
Config.Save();
}
else
Context.Respond($"{steamId} is not whitelisted.");
}
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Documents;
using System.Windows.Media;
using NLog;
using NLog.Targets;
namespace Torch.Server
{
/// <summary>
/// NLog target that writes to a <see cref="FlowDocument"/>.
/// </summary>
[Target("flowDocument")]
public sealed class FlowDocumentTarget : TargetWithLayout
{
private FlowDocument _document = new FlowDocument { Background = new SolidColorBrush(Colors.Black) };
private readonly Paragraph _paragraph = new Paragraph();
private readonly int _maxLines = 500;
public FlowDocument Document => _document;
public FlowDocumentTarget()
{
_document.Blocks.Add(_paragraph);
}
/// <inheritdoc />
protected override void Write(LogEventInfo logEvent)
{
_document.Dispatcher.BeginInvoke(() =>
{
var message = $"{Layout.Render(logEvent)}\n";
_paragraph.Inlines.Add(new Run(message) {Foreground = LogLevelColors[logEvent.Level]});
// A massive paragraph slows the UI down
if (_paragraph.Inlines.Count > _maxLines)
_paragraph.Inlines.Remove(_paragraph.Inlines.FirstInline);
});
}
private static readonly Dictionary<LogLevel, SolidColorBrush> LogLevelColors = new Dictionary<LogLevel, SolidColorBrush>
{
[LogLevel.Trace] = new SolidColorBrush(Colors.DimGray),
[LogLevel.Debug] = new SolidColorBrush(Colors.DarkGray),
[LogLevel.Info] = new SolidColorBrush(Colors.White),
[LogLevel.Warn] = new SolidColorBrush(Colors.Magenta),
[LogLevel.Error] = new SolidColorBrush(Colors.Yellow),
[LogLevel.Fatal] = new SolidColorBrush(Colors.Red),
};
}
}

238
Torch.Server/Initializer.cs Normal file
View File

@@ -0,0 +1,238 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using NLog;
using NLog.Targets;
using Sandbox.Engine.Utils;
using Torch.Utils;
using VRage.FileSystem;
using VRage.Library.Exceptions;
namespace Torch.Server
{
public class Initializer
{
private static readonly Logger Log = LogManager.GetLogger(nameof(Initializer));
private bool _init;
private const string STEAMCMD_DIR = "steamcmd";
private const string STEAMCMD_ZIP = "temp.zip";
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";
private static readonly string RUNSCRIPT_PATH = $"{STEAMCMD_DIR}\\runscript.txt";
private const string RUNSCRIPT = @"force_install_dir ../
login anonymous
app_update 298740
quit";
private TorchConfig _config;
private TorchServer _server;
private string _basePath;
public TorchConfig Config => _config;
public TorchServer Server => _server;
public Initializer(string basePath)
{
_basePath = basePath;
}
public bool Initialize(string[] args)
{
if (_init)
return false;
#if !DEBUG
AppDomain.CurrentDomain.UnhandledException += HandleException;
#endif
// This is what happens when Keen is bad and puts extensions into the System namespace.
if (!Enumerable.Contains(args, "-noupdate"))
RunSteamCmd();
var basePath = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
var apiSource = Path.Combine(basePath, "DedicatedServer64", "steam_api64.dll");
var apiTarget = Path.Combine(basePath, "steam_api64.dll");
if (!File.Exists(apiTarget))
File.Copy(apiSource, apiTarget);
_config = InitConfig();
if (!_config.Parse(args))
return false;
if (!string.IsNullOrEmpty(_config.WaitForPID))
{
try
{
var pid = int.Parse(_config.WaitForPID);
var waitProc = Process.GetProcessById(pid);
Log.Info("Continuing in 5 seconds.");
Log.Warn($"Waiting for process {pid} to close");
while (!waitProc.HasExited)
{
Console.Write(".");
Thread.Sleep(1000);
}
}
catch
{
// ignored
}
}
_init = true;
return true;
}
public void Run()
{
_server = new TorchServer(_config);
var init = Task.Run(() => _server.Init()).ContinueWith(x =>
{
if (!x.IsFaulted)
return;
Log.Error("Error initializing server.");
LogException(x.Exception);
});
if (!_config.NoGui)
{
if (_config.Autostart)
init.ContinueWith(x => _server.Start());
Log.Info("Showing UI");
Console.SetOut(TextWriter.Null);
NativeMethods.FreeConsole();
new TorchUI(_server).ShowDialog();
}
else
{
init.Wait();
_server.Start();
}
}
private TorchConfig InitConfig()
{
var configName = "Torch.cfg";
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
if (File.Exists(configName))
{
Log.Info($"Loading config {configPath}");
return TorchConfig.LoadFrom(configPath);
}
else
{
Log.Info($"Generating default config at {configPath}");
var config = new TorchConfig {InstancePath = Path.GetFullPath("Instance")};
config.Save(configPath);
return config;
}
}
public static void RunSteamCmd()
{
var log = LogManager.GetLogger("SteamCMD");
if (!Directory.Exists(STEAMCMD_DIR))
{
Directory.CreateDirectory(STEAMCMD_DIR);
}
if (!File.Exists(RUNSCRIPT_PATH))
File.WriteAllText(RUNSCRIPT_PATH, RUNSCRIPT);
if (!File.Exists(STEAMCMD_PATH))
{
try
{
log.Info("Downloading SteamCMD.");
using (var client = new WebClient())
client.DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", STEAMCMD_ZIP);
ZipFile.ExtractToDirectory(STEAMCMD_ZIP, STEAMCMD_DIR);
File.Delete(STEAMCMD_ZIP);
log.Info("SteamCMD downloaded successfully!");
}
catch
{
log.Error("Failed to download SteamCMD, unable to update the DS.");
return;
}
}
log.Info("Checking for DS updates.");
var steamCmdProc = new ProcessStartInfo(STEAMCMD_PATH, "+runscript runscript.txt")
{
WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), STEAMCMD_DIR),
UseShellExecute = false,
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.ASCII
};
var cmd = Process.Start(steamCmdProc);
// ReSharper disable once PossibleNullReferenceException
while (!cmd.HasExited)
{
log.Info(cmd.StandardOutput.ReadLine());
Thread.Sleep(100);
}
}
private void LogException(Exception ex)
{
if (ex.InnerException != null)
{
LogException(ex.InnerException);
}
Log.Fatal(ex);
if (ex is ReflectionTypeLoadException exti)
foreach (Exception exl in exti.LoaderExceptions)
LogException(exl);
if (ex is AggregateException ag)
foreach (Exception e in ag.InnerExceptions)
LogException(e);
}
private void HandleException(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception)e.ExceptionObject;
LogException(ex);
if (MyFakes.ENABLE_MINIDUMP_SENDING)
{
string path = Path.Combine(MyFileSystem.UserDataPath, "Minidump.dmp");
Log.Info($"Generating minidump at {path}");
MyMiniDump.Options options = MyMiniDump.Options.WithProcessThreadData | MyMiniDump.Options.WithThreadInfo;
MyMiniDump.Write(path, options, MyMiniDump.ExceptionInfo.Present);
}
LogManager.Flush();
if (_config.RestartOnCrash)
{
Console.WriteLine("Restarting in 5 seconds.");
Thread.Sleep(5000);
var exe = typeof(Program).Assembly.Location;
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
Process.Start(exe, _config.ToString());
}
else
{
MessageBox.Show("Torch encountered a fatal error and needs to close. Please check the logs for details.");
}
Process.GetCurrentProcess().Kill();
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace Torch.Server
{
public static class ListBoxExtensions
{
//https://stackoverflow.com/questions/28689125/how-to-autoscroll-listbox-to-bottom-wpf-c
public static void ScrollToItem(this ListBox listBox, int index)
{
// Find a container
UIElement container = null;
for (int i = index; i > 0; i--)
{
container = listBox.ItemContainerGenerator.ContainerFromIndex(i) as UIElement;
if (container != null)
{
break;
}
}
if (container == null)
return;
// Find the ScrollContentPresenter
ScrollContentPresenter presenter = null;
for (Visual vis = container; vis != null && vis != listBox; vis = VisualTreeHelper.GetParent(vis) as Visual)
if ((presenter = vis as ScrollContentPresenter) != null)
break;
if (presenter == null)
return;
// Find the IScrollInfo
var scrollInfo =
!presenter.CanContentScroll ? presenter :
presenter.Content as IScrollInfo ??
FirstVisualChild(presenter.Content as ItemsPresenter) as IScrollInfo ??
presenter;
// Find the amount of items that is "Visible" in the ListBox
var height = (container as ListBoxItem).ActualHeight;
var lbHeight = listBox.ActualHeight;
var showCount = (int)Math.Floor(lbHeight / height) - 1;
//Set the scrollbar
if (scrollInfo.CanVerticallyScroll)
scrollInfo.SetVerticalOffset(index - showCount);
}
private static DependencyObject FirstVisualChild(Visual visual)
{
if (visual == null) return null;
if (VisualTreeHelper.GetChildrenCount(visual) == 0) return null;
return VisualTreeHelper.GetChild(visual, 0);
}
}
}

View File

@@ -0,0 +1,265 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using NLog;
using NLog.Fluent;
using Torch.API;
using Torch.Collections;
using Torch.Managers;
using Torch.Server.ViewModels.Entities;
using Torch.Utils;
namespace Torch.Server.Managers
{
/// <summary>
/// Manager that lets users bind random view models to entities in Torch's Entity Manager
/// </summary>
public class EntityControlManager : Manager
{
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
/// <summary>
/// Creates an entity control manager for the given instance of torch
/// </summary>
/// <param name="torchInstance">Torch instance</param>
internal EntityControlManager(ITorchBase torchInstance) : base(torchInstance)
{
}
private abstract class ModelFactory
{
private readonly ConditionalWeakTable<EntityViewModel, EntityControlViewModel> _models = new ConditionalWeakTable<EntityViewModel, EntityControlViewModel>();
public abstract Delegate Delegate { get; }
protected abstract EntityControlViewModel Create(EntityViewModel evm);
#pragma warning disable 649
[ReflectedGetter(Name = "Keys")]
private static readonly Func<ConditionalWeakTable<EntityViewModel, EntityControlViewModel>, ICollection<EntityViewModel>> _weakTableKeys;
#pragma warning restore 649
/// <summary>
/// Warning: Creates a giant list, avoid if possible.
/// </summary>
internal ICollection<EntityViewModel> Keys => _weakTableKeys(_models);
internal EntityControlViewModel GetOrCreate(EntityViewModel evm)
{
return _models.GetValue(evm, Create);
}
internal bool TryGet(EntityViewModel evm, out EntityControlViewModel res)
{
return _models.TryGetValue(evm, out res);
}
}
private class ModelFactory<T> : ModelFactory where T : EntityViewModel
{
private readonly Func<T, EntityControlViewModel> _factory;
public override Delegate Delegate => _factory;
internal ModelFactory(Func<T, EntityControlViewModel> factory)
{
_factory = factory;
}
protected override EntityControlViewModel Create(EntityViewModel evm)
{
if (evm is T m)
{
var result = _factory(m);
_log.Trace($"Model factory {_factory.Method} created {result} for {evm}");
return result;
}
return null;
}
}
private readonly List<ModelFactory> _modelFactories = new List<ModelFactory>();
private readonly List<Delegate> _controlFactories = new List<Delegate>();
private readonly List<WeakReference<EntityViewModel>> _boundEntityViewModels = new List<WeakReference<EntityViewModel>>();
private readonly ConditionalWeakTable<EntityViewModel, MtObservableList<EntityControlViewModel>> _boundViewModels = new ConditionalWeakTable<EntityViewModel, MtObservableList<EntityControlViewModel>>();
/// <summary>
/// This factory will be used to create component models for matching entity models.
/// </summary>
/// <typeparam name="TEntityBaseModel">entity model type to match</typeparam>
/// <param name="modelFactory">Method to create component model from entity model.</param>
public void RegisterModelFactory<TEntityBaseModel>(Func<TEntityBaseModel, EntityControlViewModel> modelFactory)
where TEntityBaseModel : EntityViewModel
{
if (!typeof(TEntityBaseModel).IsAssignableFrom(modelFactory.Method.GetParameters()[0].ParameterType))
throw new ArgumentException("Generic type must match lamda type", nameof(modelFactory));
lock (this)
{
var factory = new ModelFactory<TEntityBaseModel>(modelFactory);
_modelFactories.Add(factory);
var i = 0;
while (i < _boundEntityViewModels.Count)
{
if (_boundEntityViewModels[i].TryGetTarget(out EntityViewModel target) &&
_boundViewModels.TryGetValue(target, out MtObservableList<EntityControlViewModel> components))
{
if (target is TEntityBaseModel tent)
UpdateBinding(target, components);
i++;
}
else
_boundEntityViewModels.RemoveAtFast(i);
}
}
}
/// <summary>
/// Unregisters a factory registered with <see cref="RegisterModelFactory{TEntityBaseModel}"/>
/// </summary>
/// <typeparam name="TEntityBaseModel">entity model type to match</typeparam>
/// <param name="modelFactory">Method to create component model from entity model.</param>
public void UnregisterModelFactory<TEntityBaseModel>(Func<TEntityBaseModel, EntityControlViewModel> modelFactory)
where TEntityBaseModel : EntityViewModel
{
if (!typeof(TEntityBaseModel).IsAssignableFrom(modelFactory.Method.GetParameters()[0].ParameterType))
throw new ArgumentException("Generic type must match lamda type", nameof(modelFactory));
lock (this)
{
for (var i = 0; i < _modelFactories.Count; i++)
{
if (_modelFactories[i].Delegate == (Delegate)modelFactory)
{
foreach (var entry in _modelFactories[i].Keys)
if (_modelFactories[i].TryGet(entry, out EntityControlViewModel ecvm) && ecvm != null
&& _boundViewModels.TryGetValue(entry, out var binding))
binding.Remove(ecvm);
_modelFactories.RemoveAt(i);
break;
}
}
}
}
/// <summary>
/// This factory will be used to create controls for matching view models.
/// </summary>
/// <typeparam name="TEntityComponentModel">component model to match</typeparam>
/// <param name="controlFactory">Method to create control from component model</param>
public void RegisterControlFactory<TEntityComponentModel>(
Func<TEntityComponentModel, Control> controlFactory)
where TEntityComponentModel : EntityControlViewModel
{
if (!typeof(TEntityComponentModel).IsAssignableFrom(controlFactory.Method.GetParameters()[0].ParameterType))
throw new ArgumentException("Generic type must match lamda type", nameof(controlFactory));
lock (this)
{
_controlFactories.Add(controlFactory);
RefreshControls<TEntityComponentModel>();
}
}
///<summary>
/// Unregisters a factory registered with <see cref="RegisterControlFactory{TEntityComponentModel}"/>
/// </summary>
/// <typeparam name="TEntityComponentModel">component model to match</typeparam>
/// <param name="controlFactory">Method to create control from component model</param>
public void UnregisterControlFactory<TEntityComponentModel>(
Func<TEntityComponentModel, Control> controlFactory)
where TEntityComponentModel : EntityControlViewModel
{
if (!typeof(TEntityComponentModel).IsAssignableFrom(controlFactory.Method.GetParameters()[0].ParameterType))
throw new ArgumentException("Generic type must match lamda type", nameof(controlFactory));
lock (this)
{
_controlFactories.Remove(controlFactory);
RefreshControls<TEntityComponentModel>();
}
}
private void RefreshControls<TEntityComponentModel>() where TEntityComponentModel : EntityControlViewModel
{
var i = 0;
while (i < _boundEntityViewModels.Count)
{
if (_boundEntityViewModels[i].TryGetTarget(out EntityViewModel target) &&
_boundViewModels.TryGetValue(target, out MtObservableList<EntityControlViewModel> components))
{
foreach (EntityControlViewModel component in components)
if (component is TEntityComponentModel)
component.InvalidateControl();
i++;
}
else
_boundEntityViewModels.RemoveAtFast(i);
}
}
/// <summary>
/// Gets the models bound to the given entity view model.
/// </summary>
/// <param name="entity">view model to query</param>
/// <returns></returns>
public MtObservableList<EntityControlViewModel> BoundModels(EntityViewModel entity)
{
return _boundViewModels.GetValue(entity, CreateFreshBinding);
}
/// <summary>
/// Gets a control for the given view model type.
/// </summary>
/// <param name="model">model to create a control for</param>
/// <returns>control, or null if none</returns>
public Control CreateControl(EntityControlViewModel model)
{
lock (this)
foreach (Delegate factory in _controlFactories)
if (factory.Method.GetParameters()[0].ParameterType.IsInstanceOfType(model) &&
factory.DynamicInvoke(model) is Control result)
{
_log.Trace($"Control factory {factory.Method} created {result}");
return result;
}
_log.Warn($"No control created for {model}");
return null;
}
private MtObservableList<EntityControlViewModel> CreateFreshBinding(EntityViewModel key)
{
var binding = new MtObservableList<EntityControlViewModel>();
lock (this)
{
_boundEntityViewModels.Add(new WeakReference<EntityViewModel>(key));
}
binding.PropertyChanged += (x, args) =>
{
if (nameof(binding.IsObserved).Equals(args.PropertyName))
UpdateBinding(key, binding);
};
return binding;
}
private void UpdateBinding(EntityViewModel key, MtObservableList<EntityControlViewModel> binding)
{
if (!binding.IsObserved)
return;
lock (this)
{
foreach (ModelFactory factory in _modelFactories)
{
var result = factory.GetOrCreate(key);
if (result != null && !binding.Contains(result))
binding.Add(result);
}
}
}
}
}

View File

@@ -10,41 +10,48 @@ using Havok;
using NLog; using NLog;
using Sandbox.Engine.Networking; using Sandbox.Engine.Networking;
using Sandbox.Engine.Utils; using Sandbox.Engine.Utils;
using Sandbox.Game;
using Sandbox.Game.Gui;
using Torch.API; using Torch.API;
using Torch.API.Managers; using Torch.API.Managers;
using Torch.Managers; using Torch.Managers;
using Torch.Mod;
using Torch.Server.ViewModels; using Torch.Server.ViewModels;
using VRage;
using VRage.FileSystem; using VRage.FileSystem;
using VRage.Game; using VRage.Game;
using VRage.Game.ObjectBuilder;
using VRage.ObjectBuilders; using VRage.ObjectBuilders;
using VRage.Plugins;
namespace Torch.Server.Managers namespace Torch.Server.Managers
{ {
public class InstanceManager : Manager public class InstanceManager : Manager
{ {
private const string CONFIG_NAME = "SpaceEngineers-Dedicated.cfg"; private const string CONFIG_NAME = "SpaceEngineers-Dedicated.cfg";
public event Action<ConfigDedicatedViewModel> InstanceLoaded;
public ConfigDedicatedViewModel DedicatedConfig { get; set; } public ConfigDedicatedViewModel DedicatedConfig { get; set; }
private static readonly Logger Log = LogManager.GetLogger(nameof(InstanceManager)); private static readonly Logger Log = LogManager.GetLogger(nameof(InstanceManager));
[Dependency]
private FilesystemManager _filesystemManager;
public InstanceManager(ITorchBase torchInstance) : base(torchInstance) public InstanceManager(ITorchBase torchInstance) : base(torchInstance)
{ {
} }
/// <inheritdoc />
public override void Init()
{
LoadInstance(Torch.Config.InstancePath);
}
public void LoadInstance(string path, bool validate = true) public void LoadInstance(string path, bool validate = true)
{ {
Log.Info($"Loading instance {path}");
if (validate) if (validate)
ValidateInstance(path); ValidateInstance(path);
MyFileSystem.Reset(); MyFileSystem.Reset();
MyFileSystem.ExePath = Path.Combine(Torch.GetManager<FilesystemManager>().TorchDirectory, "DedicatedServer64");
MyFileSystem.Init("Content", path); MyFileSystem.Init("Content", path);
//Initializes saves path. Why this isn't in Init() we may never know.
MyFileSystem.InitUserSpecific(null);
var configPath = Path.Combine(path, CONFIG_NAME); var configPath = Path.Combine(path, CONFIG_NAME);
if (!File.Exists(configPath)) if (!File.Exists(configPath))
@@ -57,35 +64,77 @@ namespace Torch.Server.Managers
config.Load(configPath); config.Load(configPath);
DedicatedConfig = new ConfigDedicatedViewModel(config); DedicatedConfig = new ConfigDedicatedViewModel(config);
var worldFolders = Directory.EnumerateDirectories(Path.Combine(Torch.Config.InstancePath, "Saves")); var worldFolders = Directory.EnumerateDirectories(Path.Combine(Torch.Config.InstancePath, "Saves"));
foreach (var f in worldFolders) foreach (var f in worldFolders)
DedicatedConfig.WorldPaths.Add(f); {
if (!string.IsNullOrEmpty(f) && File.Exists(Path.Combine(f, "Sandbox.sbc")))
DedicatedConfig.Worlds.Add(new WorldViewModel(f));
}
if (DedicatedConfig.WorldPaths.Count == 0) if (DedicatedConfig.Worlds.Count == 0)
{ {
Log.Warn($"No worlds found in the current instance {path}."); Log.Warn($"No worlds found in the current instance {path}.");
return; return;
} }
/* SelectWorld(DedicatedConfig.LoadWorld ?? DedicatedConfig.Worlds.First().WorldPath, false);
if (string.IsNullOrEmpty(DedicatedConfig.LoadWorld))
{ InstanceLoaded?.Invoke(DedicatedConfig);
Log.Warn("No world specified, importing first available world.");
SelectWorld(DedicatedConfig.WorldPaths[0], false);
}*/
} }
public void SelectWorld(string worldPath, bool modsOnly = true) public void SelectWorld(string worldPath, bool modsOnly = true)
{ {
DedicatedConfig.LoadWorld = worldPath; DedicatedConfig.LoadWorld = worldPath;
LoadWorldMods(modsOnly); DedicatedConfig.SelectedWorld = DedicatedConfig.Worlds.FirstOrDefault(x => x.WorldPath == worldPath);
if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
{
DedicatedConfig.Mods.Clear();
//remove the Torch mod to avoid running multiple copies of it
DedicatedConfig.SelectedWorld.Checkpoint.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods)
DedicatedConfig.Mods.Add(m.PublishedFileId);
}
} }
public void SelectWorld(WorldViewModel world, bool modsOnly = true)
private void LoadWorldMods(bool modsOnly = true)
{ {
if (DedicatedConfig.LoadWorld == null) DedicatedConfig.LoadWorld = world.WorldPath;
DedicatedConfig.SelectedWorld = world;
if (DedicatedConfig.SelectedWorld?.Checkpoint != null)
{
DedicatedConfig.Mods.Clear();
//remove the Torch mod to avoid running multiple copies of it
DedicatedConfig.SelectedWorld.Checkpoint.Mods.RemoveAll(m => m.PublishedFileId == TorchModCore.MOD_ID);
foreach (var m in DedicatedConfig.SelectedWorld.Checkpoint.Mods)
DedicatedConfig.Mods.Add(m.PublishedFileId);
}
}
public void ImportSelectedWorldConfig()
{
ImportWorldConfig(DedicatedConfig.SelectedWorld, false);
}
private void ImportWorldConfig(WorldViewModel world, bool modsOnly = true)
{
var sb = new StringBuilder();
foreach (var mod in world.Checkpoint.Mods)
sb.AppendLine(mod.PublishedFileId.ToString());
DedicatedConfig.Mods = world.Checkpoint.Mods.Select(x => x.PublishedFileId).ToList();
Log.Debug("Loaded mod list from world");
if (!modsOnly)
DedicatedConfig.SessionSettings = world.Checkpoint.Settings;
}
private void ImportWorldConfig(bool modsOnly = true)
{
if (string.IsNullOrEmpty(DedicatedConfig.LoadWorld))
return; return;
var sandboxPath = Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc"); var sandboxPath = Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc");
@@ -93,44 +142,64 @@ namespace Torch.Server.Managers
if (!File.Exists(sandboxPath)) if (!File.Exists(sandboxPath))
return; return;
try
{
MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes); MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
if (checkpoint == null) if (checkpoint == null)
{ {
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})"); Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {Torch.Config.InstancePath})");
return; return;
} }
var sb = new StringBuilder(); DedicatedConfig.Mods = checkpoint.Mods.Select(x => x.PublishedFileId).ToList();
foreach (var mod in checkpoint.Mods)
sb.AppendLine(mod.PublishedFileId.ToString());
DedicatedConfig.Mods = sb.ToString(); Log.Debug("Loaded mod list from world");
Log.Info("Loaded mod list from world");
if (!modsOnly) if (!modsOnly)
DedicatedConfig.SessionSettings = new SessionSettingsViewModel(checkpoint.Settings); DedicatedConfig.SessionSettings = new SessionSettingsViewModel(checkpoint.Settings);
} }
catch (Exception e)
{
Log.Error($"Error loading mod list from world, verify that your mod list is accurate. '{DedicatedConfig.LoadWorld}'.");
Log.Error(e);
}
}
public void SaveConfig() public void SaveConfig()
{ {
DedicatedConfig.Model.Save(); var cf = Torch.Config as TorchConfig;
if (cf?.ReservedPlayers?.Count > 0)
{
foreach (var res in cf.ReservedPlayers)
{
if (!DedicatedConfig.Reserved.Contains(res))
DedicatedConfig.Reserved.Add(res);
}
}
DedicatedConfig.Save(Path.Combine(Torch.Config.InstancePath, CONFIG_NAME));
Log.Info("Saved dedicated config."); Log.Info("Saved dedicated config.");
try try
{ {
MyObjectBuilderSerializer.DeserializeXML(Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc"), out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes); var sandboxPath = Path.Combine(DedicatedConfig.LoadWorld, "Sandbox.sbc");
MyObjectBuilderSerializer.DeserializeXML(sandboxPath, out MyObjectBuilder_Checkpoint checkpoint, out ulong sizeInBytes);
if (checkpoint == null) if (checkpoint == null)
{ {
Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {TorchBase.Instance.Config.InstancePath})"); Log.Error($"Failed to load {DedicatedConfig.LoadWorld}, checkpoint null ({sizeInBytes} bytes, instance {Torch.Config.InstancePath})");
return; return;
} }
checkpoint.SessionName = DedicatedConfig.WorldName;
checkpoint.Settings = DedicatedConfig.SessionSettings; checkpoint.Settings = DedicatedConfig.SessionSettings;
checkpoint.Mods.Clear(); checkpoint.Mods.Clear();
foreach (var modId in DedicatedConfig.Model.Mods)
foreach (var modId in DedicatedConfig.Mods)
checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId)); checkpoint.Mods.Add(new MyObjectBuilder_Checkpoint.ModItem(modId));
MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld); MyObjectBuilderSerializer.SerializeXML(sandboxPath, false, checkpoint);
//MyLocalCache.SaveCheckpoint(checkpoint, DedicatedConfig.LoadWorld);
Log.Info("Saved world config."); Log.Info("Saved world config.");
} }
catch (Exception e) catch (Exception e)
@@ -155,4 +224,44 @@ namespace Torch.Server.Managers
config.Save(configPath); config.Save(configPath);
} }
} }
public class WorldViewModel : ViewModel
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public string FolderName { get; set; }
public string WorldPath { get; }
public long WorldSizeKB { get; }
private string _checkpointPath;
public CheckpointViewModel Checkpoint { get; private set; }
public WorldViewModel(string worldPath)
{
WorldPath = worldPath;
WorldSizeKB = new DirectoryInfo(worldPath).GetFiles().Sum(x => x.Length) / 1024;
_checkpointPath = Path.Combine(WorldPath, "Sandbox.sbc");
FolderName = Path.GetFileName(worldPath);
BeginLoadCheckpoint();
}
public async Task SaveCheckpointAsync()
{
await Task.Run(() =>
{
using (var f = File.Open(_checkpointPath, FileMode.Create))
MyObjectBuilderSerializer.SerializeXML(f, Checkpoint);
});
}
private void BeginLoadCheckpoint()
{
//Task.Run(() =>
{
Log.Info($"Preloading checkpoint {_checkpointPath}");
MyObjectBuilderSerializer.DeserializeXML(_checkpointPath, out MyObjectBuilder_Checkpoint checkpoint);
Checkpoint = new CheckpointViewModel(checkpoint);
OnPropertyChanged(nameof(Checkpoint));
}//);
}
}
} }

View File

@@ -0,0 +1,301 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using NLog;
using NLog.Fluent;
using Sandbox;
using Sandbox.Engine.Multiplayer;
using Sandbox.Engine.Networking;
using Sandbox.Game.World;
using Steamworks;
using Torch.API;
using Torch.API.Managers;
using Torch.Managers;
using Torch.Utils;
using Torch.ViewModels;
using VRage.Game;
using VRage.Game.ModAPI;
using VRage.GameServices;
using VRage.Network;
using VRage.Steam;
namespace Torch.Server.Managers
{
public class MultiplayerManagerDedicated : MultiplayerManagerBase, IMultiplayerManagerServer
{
private static readonly Logger _log = LogManager.GetCurrentClassLogger();
#pragma warning disable 649
[ReflectedGetter(Name = "m_members")]
private static Func<MyDedicatedServerBase, List<ulong>> _members;
[ReflectedGetter(Name = "m_waitingForGroup")]
private static Func<MyDedicatedServerBase, HashSet<ulong>> _waitingForGroup;
#pragma warning restore 649
/// <inheritdoc />
public IReadOnlyList<ulong> BannedPlayers => MySandboxGame.ConfigDedicated.Banned;
private Dictionary<ulong, ulong> _gameOwnerIds = new Dictionary<ulong, ulong>();
[Dependency]
private InstanceManager _instanceManager;
/// <inheritdoc />
public MultiplayerManagerDedicated(ITorchBase torch) : base(torch)
{
}
/// <inheritdoc />
public void KickPlayer(ulong steamId) => Torch.Invoke(() => MyMultiplayer.Static.KickClient(steamId));
/// <inheritdoc />
public void BanPlayer(ulong steamId, bool banned = true)
{
Torch.Invoke(() =>
{
MyMultiplayer.Static.BanClient(steamId, banned);
});
}
internal void RaiseClientBanned(ulong user, bool banned)
{
PlayerBanned?.Invoke(user, banned);
Torch.Invoke(() =>
{
if(_gameOwnerIds.TryGetValue(user, out ulong owner))
MyMultiplayer.Static.BanClient(owner, banned);
});
}
internal void RaiseClientKicked(ulong user)
{
PlayerKicked?.Invoke(user);
}
/// <inheritdoc />
public bool IsBanned(ulong steamId) => _isClientBanned.Invoke(MyMultiplayer.Static, steamId) ||
MySandboxGame.ConfigDedicated.Banned.Contains(steamId);
/// <inheritdoc />
public event Action<ulong> PlayerKicked;
/// <inheritdoc />
public event Action<ulong, bool> PlayerBanned;
/// <inheritdoc/>
public override void Attach()
{
base.Attach();
_gameServerValidateAuthTicketReplacer = _gameServerValidateAuthTicketFactory.Invoke();
_gameServerUserGroupStatusReplacer = _gameServerUserGroupStatusFactory.Invoke();
_gameServerValidateAuthTicketReplacer.Replace(
new Action<ulong, JoinResult, ulong>(ValidateAuthTicketResponse), MyGameService.GameServer);
_gameServerUserGroupStatusReplacer.Replace(new Action<ulong, ulong, bool, bool>(UserGroupStatusResponse),
MyGameService.GameServer);
_log.Info("Inserted steam authentication intercept");
}
/// <inheritdoc/>
public override void Detach()
{
if (_gameServerValidateAuthTicketReplacer != null && _gameServerValidateAuthTicketReplacer.Replaced)
_gameServerValidateAuthTicketReplacer.Restore(MyGameService.GameServer);
if (_gameServerUserGroupStatusReplacer != null && _gameServerUserGroupStatusReplacer.Replaced)
_gameServerUserGroupStatusReplacer.Restore(MyGameService.GameServer);
_log.Info("Removed steam authentication intercept");
base.Detach();
}
#pragma warning disable 649
[ReflectedEventReplace(typeof(MySteamGameServer), nameof(MySteamGameServer.ValidateAuthTicketResponse),
typeof(MyDedicatedServerBase), "GameServer_ValidateAuthTicketResponse")]
private static Func<ReflectedEventReplacer> _gameServerValidateAuthTicketFactory;
[ReflectedEventReplace(typeof(MySteamGameServer), nameof(MySteamGameServer.UserGroupStatusResponse),
typeof(MyDedicatedServerBase), "GameServer_UserGroupStatus")]
private static Func<ReflectedEventReplacer> _gameServerUserGroupStatusFactory;
private ReflectedEventReplacer _gameServerValidateAuthTicketReplacer;
private ReflectedEventReplacer _gameServerUserGroupStatusReplacer;
#pragma warning restore 649
#region CustomAuth
#pragma warning disable 649
[ReflectedStaticMethod(Type = typeof(MyDedicatedServerBase), Name = "ConvertSteamIDFrom64")]
private static Func<ulong, string> _convertSteamIDFrom64;
[ReflectedStaticMethod(Type = typeof(MyGameService), Name = "GetServerAccountType")]
private static Func<ulong, MyGameServiceAccountType> _getServerAccountType;
[ReflectedMethod(Name = "UserAccepted")]
private static Action<MyDedicatedServerBase, ulong> _userAcceptedImpl;
[ReflectedMethod(Name = "UserRejected")]
private static Action<MyDedicatedServerBase, ulong, JoinResult> _userRejected;
[ReflectedMethod(Name = "IsClientBanned")]
private static Func<MyMultiplayerBase, ulong, bool> _isClientBanned;
[ReflectedMethod(Name = "IsClientKicked")]
private static Func<MyMultiplayerBase, ulong, bool> _isClientKicked;
[ReflectedMethod(Name = "RaiseClientKicked")]
private static Action<MyMultiplayerBase, ulong> _raiseClientKicked;
#pragma warning restore 649
private const int _waitListSize = 32;
private readonly List<WaitingForGroup> _waitingForGroupLocal = new List<WaitingForGroup>(_waitListSize);
private struct WaitingForGroup
{
public readonly ulong SteamId;
public readonly JoinResult Response;
public readonly ulong SteamOwner;
public WaitingForGroup(ulong id, JoinResult response, ulong owner)
{
SteamId = id;
Response = response;
SteamOwner = owner;
}
}
//Largely copied from SE
private void ValidateAuthTicketResponse(ulong steamId, JoinResult response, ulong steamOwner)
{
var state = new MyP2PSessionState();
MySteamService.Static.Peer2Peer.GetSessionState(steamId, ref state);
var ip = new IPAddress(BitConverter.GetBytes(state.RemoteIP).Reverse().ToArray());
Torch.CurrentSession.KeenSession.PromotedUsers.TryGetValue(steamId, out MyPromoteLevel promoteLevel);
_log.Debug($"ValidateAuthTicketResponse(user={steamId}, response={response}, owner={steamOwner}, permissions={promoteLevel})");
_log.Info($"Connection attempt by {steamId} from {ip}");
if (Torch.CurrentSession.KeenSession.OnlineMode == MyOnlineModeEnum.OFFLINE &&
promoteLevel < MyPromoteLevel.Admin)
{
_log.Warn($"Rejecting user {steamId}, world is set to offline and user is not admin.");
UserRejected(steamId, JoinResult.TicketCanceled);
}
else if (MySandboxGame.ConfigDedicated.GroupID == 0uL)
RunEvent(new ValidateAuthTicketEvent(steamId, steamOwner, response, 0, true, false));
else if (_getServerAccountType(MySandboxGame.ConfigDedicated.GroupID) != MyGameServiceAccountType.Clan)
UserRejected(steamId, JoinResult.GroupIdInvalid);
else if (MyGameService.GameServer.RequestGroupStatus(steamId, MySandboxGame.ConfigDedicated.GroupID))
lock (_waitingForGroupLocal)
{
if (_waitingForGroupLocal.Count >= _waitListSize)
_waitingForGroupLocal.RemoveAt(0);
_waitingForGroupLocal.Add(new WaitingForGroup(steamId, response, steamOwner));
}
else
UserRejected(steamId, JoinResult.SteamServersOffline);
}
private void RunEvent(ValidateAuthTicketEvent info)
{
JoinResult internalAuth;
if (IsBanned(info.SteamOwner) || IsBanned(info.SteamID))
internalAuth = JoinResult.BannedByAdmins;
else if (_isClientKicked(MyMultiplayer.Static, info.SteamID) ||
_isClientKicked(MyMultiplayer.Static, info.SteamOwner))
internalAuth = JoinResult.KickedRecently;
else if (info.SteamResponse == JoinResult.OK)
{
var config = (TorchConfig) Torch.Config;
if (config.EnableWhitelist && !config.Whitelist.Contains(info.SteamID))
{
_log.Warn($"Rejecting user {info.SteamID} because they are not whitelisted in Torch.cfg.");
internalAuth = JoinResult.NotInGroup;
}
else if (MySandboxGame.ConfigDedicated.Reserved.Contains(info.SteamID))
internalAuth = JoinResult.OK;
//Admins can bypass member limit
else if (MySandboxGame.ConfigDedicated.Administrators.Contains(info.SteamID.ToString()) ||
MySandboxGame.ConfigDedicated.Administrators.Contains(_convertSteamIDFrom64(info.SteamID)))
internalAuth = JoinResult.OK;
//Server counts as a client, so subtract 1 from MemberCount
else if (MyMultiplayer.Static.MemberLimit > 0 &&
MyMultiplayer.Static.MemberCount - 1 >= MyMultiplayer.Static.MemberLimit)
internalAuth = JoinResult.ServerFull;
else if (MySandboxGame.ConfigDedicated.GroupID == 0uL)
internalAuth = JoinResult.OK;
else
{
if (MySandboxGame.ConfigDedicated.GroupID == info.Group && (info.Member || info.Officer))
internalAuth = JoinResult.OK;
else
internalAuth = JoinResult.NotInGroup;
}
}
else
internalAuth = info.SteamResponse;
info.FutureVerdict = Task.FromResult(internalAuth);
MultiplayerManagerDedicatedEventShim.RaiseValidateAuthTicket(ref info);
info.FutureVerdict.ContinueWith((task) =>
{
JoinResult verdict;
if (task.IsFaulted)
{
_log.Error(task.Exception, $"Future validation verdict faulted");
verdict = JoinResult.TicketCanceled;
}
else
verdict = task.Result;
Torch.Invoke(() => { CommitVerdict(info.SteamID, verdict); });
});
}
private void CommitVerdict(ulong steamId, JoinResult verdict)
{
if (verdict == JoinResult.OK)
UserAccepted(steamId);
else
UserRejected(steamId, verdict);
}
private void UserGroupStatusResponse(ulong userId, ulong groupId, bool member, bool officer)
{
lock (_waitingForGroupLocal)
for (var j = 0; j < _waitingForGroupLocal.Count; j++)
{
var wait = _waitingForGroupLocal[j];
if (wait.SteamId == userId)
{
RunEvent(new ValidateAuthTicketEvent(wait.SteamId, wait.SteamOwner, wait.Response, groupId,
member, officer));
_waitingForGroupLocal.RemoveAt(j);
break;
}
}
}
private void UserRejected(ulong steamId, JoinResult reason)
{
_userRejected.Invoke((MyDedicatedServerBase) MyMultiplayer.Static, steamId, reason);
}
private void UserAccepted(ulong steamId)
{
_userAcceptedImpl.Invoke((MyDedicatedServerBase) MyMultiplayer.Static, steamId);
base.RaiseClientJoined(steamId);
}
#endregion
}
}

View File

@@ -0,0 +1,84 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using Sandbox;
using Torch.API.Event;
using Torch.Event;
using VRage.Network;
namespace Torch.Server.Managers
{
[EventShim]
internal static class MultiplayerManagerDedicatedEventShim
{
private static readonly EventList<ValidateAuthTicketEvent> _eventValidateAuthTicket =
new EventList<ValidateAuthTicketEvent>();
internal static void RaiseValidateAuthTicket(ref ValidateAuthTicketEvent info)
{
_eventValidateAuthTicket?.RaiseEvent(ref info);
}
}
/// <summary>
/// Event that occurs when a player tries to connect to a dedicated server.
/// Use these values to choose a <see cref="ValidateAuthTicketEvent.FutureVerdict"/>,
/// or leave it unset to allow the default logic to handle the request.
/// </summary>
public struct ValidateAuthTicketEvent : IEvent
{
/// <summary>
/// SteamID of the player
/// </summary>
public readonly ulong SteamID;
/// <summary>
/// SteamID of the game owner
/// </summary>
public readonly ulong SteamOwner;
/// <summary>
/// The response from steam
/// </summary>
public readonly JoinResult SteamResponse;
/// <summary>
/// ID of the queried group, or <c>0</c> if no group.
/// </summary>
public readonly ulong Group;
/// <summary>
/// Is this person a member of <see cref="Group"/>. If no group this is true.
/// </summary>
public readonly bool Member;
/// <summary>
/// Is this person an officer of <see cref="Group"/>. If no group this is false.
/// </summary>
public readonly bool Officer;
/// <summary>
/// A future verdict on this authorization request. If null, let the default logic choose. If not async use <see cref="Task.FromResult{TResult}(TResult)"/>
/// </summary>
public Task<JoinResult> FutureVerdict;
internal ValidateAuthTicketEvent(ulong steamId, ulong steamOwner, JoinResult steamResponse,
ulong serverGroup, bool member, bool officer)
{
SteamID = steamId;
SteamOwner = steamOwner;
SteamResponse = steamResponse;
Group = serverGroup;
Member = member;
Officer = officer;
FutureVerdict = null;
}
/// <inheritdoc/>
public bool Cancelled => FutureVerdict != null;
}
}

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NLog;
using Sandbox.Engine.Multiplayer;
using Torch.Managers.PatchManager;
using Torch.API.Managers;
namespace Torch.Server.Managers
{
[PatchShim]
internal static class MultiplayerManagerDedicatedPatchShim
{
public static void Patch(PatchContext ctx)
{
ctx.GetPattern(typeof(MyDedicatedServerBase).GetMethod(nameof(MyDedicatedServerBase.BanClient))).Prefixes.Add(typeof(MultiplayerManagerDedicatedPatchShim).GetMethod(nameof(BanPrefix)));
ctx.GetPattern(typeof(MyDedicatedServerBase).GetMethod(nameof(MyDedicatedServerBase.KickClient))).Prefixes.Add(typeof(MultiplayerManagerDedicatedPatchShim).GetMethod(nameof(KickPrefix)));
}
public static void BanPrefix(ulong userId, bool banned)
{
TorchBase.Instance.CurrentSession.Managers.GetManager<MultiplayerManagerDedicated>().RaiseClientBanned(userId, banned);
}
public static void KickPrefix(ulong userId)
{
TorchBase.Instance.CurrentSession.Managers.GetManager<MultiplayerManagerDedicated>().RaiseClientKicked(userId);
}
}
}

View File

@@ -0,0 +1,49 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace Torch.Server
{
public class MultiTextWriter : TextWriter
{
private IEnumerable<TextWriter> writers;
public MultiTextWriter(IEnumerable<TextWriter> writers)
{
this.writers = writers.ToList();
}
public MultiTextWriter(params TextWriter[] writers)
{
this.writers = writers;
}
public override void Write(char value)
{
foreach (var writer in writers)
writer.Write(value);
}
public override void Write(string value)
{
foreach (var writer in writers)
writer.Write(value);
}
public override void Flush()
{
foreach (var writer in writers)
writer.Flush();
}
public override void Close()
{
foreach (var writer in writers)
writer.Close();
}
public override Encoding Encoding
{
get { return Encoding.ASCII; }
}
}
}

View File

@@ -1,295 +1,50 @@
using System; using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.IO.Compression;
using System.Net;
using System.Reflection; using System.Reflection;
using System.ServiceProcess; using System.ServiceProcess;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using NLog; using NLog;
using Sandbox.Game.World; using NLog.Targets;
using Sandbox.ModAPI; using Torch.Utils;
using Torch;
using Torch.API;
using Torch.Server.Views;
using VRage.Game.ModAPI;
using System.IO.Compression;
using System.Net;
using System.Security.Policy;
using Torch.Server.Managers;
using VRage.FileSystem;
using VRageRender;
namespace Torch.Server namespace Torch.Server
{ {
internal static class Program internal static class Program
{ {
private static ITorchServer _server; /// <remarks>
private static Logger _log = LogManager.GetLogger("Torch");
private static bool _restartOnCrash;
private static TorchConfig _config;
private static bool _steamCmdDone;
/// <summary>
/// This method must *NOT* load any types/assemblies from the vanilla game, otherwise automatic updates will fail. /// This method must *NOT* load any types/assemblies from the vanilla game, otherwise automatic updates will fail.
/// </summary> /// </remarks>
[STAThread] [STAThread]
public static void Main(string[] args) public static void Main(string[] args)
{ {
Target.Register<FlowDocumentTarget>("FlowDocument");
//Ensures that all the files are downloaded in the Torch directory. //Ensures that all the files are downloaded in the Torch directory.
Directory.SetCurrentDirectory(new FileInfo(typeof(Program).Assembly.Location).Directory.ToString()); var workingDir = new FileInfo(typeof(Program).Assembly.Location).Directory.ToString();
var binDir = Path.Combine(workingDir, "DedicatedServer64");
Directory.SetCurrentDirectory(workingDir);
foreach (var file in Directory.GetFiles(Directory.GetCurrentDirectory(), "*.old")) if (!TorchLauncher.IsTorchWrapped())
File.Delete(file); {
TorchLauncher.Launch(Assembly.GetEntryAssembly().FullName, args, binDir);
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; return;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; }
if (!Environment.UserInteractive) if (!Environment.UserInteractive)
{ {
using (var service = new TorchService()) using (var service = new TorchService())
{
ServiceBase.Run(service); ServiceBase.Run(service);
}
return; return;
} }
//CommandLine reflection triggers assembly loading, so DS update must be completely separated. var initializer = new Initializer(workingDir);
if (!args.Contains("-noupdate")) if (!initializer.Initialize(args))
{
if (!Directory.Exists("DedicatedServer64"))
{
_log.Error("Game libraries not found. Press the Enter key to install the dedicated server.");
Console.ReadLine();
}
RunSteamCmd();
}
InitConfig();
if (!_config.Parse(args))
return; return;
if (!string.IsNullOrEmpty(_config.WaitForPID)) initializer.Run();
{
try
{
var pid = int.Parse(_config.WaitForPID);
var waitProc = Process.GetProcessById(pid);
_log.Warn($"Waiting for process {pid} to exit.");
waitProc.WaitForExit();
_log.Info("Continuing in 5 seconds.");
Thread.Sleep(5000);
}
catch
{
// ignored
}
}
_restartOnCrash = _config.RestartOnCrash;
RunServer(_config);
}
public static void InitConfig()
{
var configName = "Torch.cfg";
var configPath = Path.Combine(Directory.GetCurrentDirectory(), configName);
if (File.Exists(configName))
{
_log.Info($"Loading config {configPath}");
_config = TorchConfig.LoadFrom(configPath);
}
else
{
_log.Info($"Generating default config at {configPath}");
_config = new TorchConfig { InstancePath = Path.GetFullPath("Instance") };
_config.Save(configPath);
}
}
private const string STEAMCMD_DIR = "steamcmd";
private const string STEAMCMD_ZIP = "temp.zip";
private static readonly string STEAMCMD_PATH = $"{STEAMCMD_DIR}\\steamcmd.exe";
private static readonly string RUNSCRIPT_PATH = $"{STEAMCMD_DIR}\\runscript.txt";
private const string RUNSCRIPT = @"force_install_dir ../
login anonymous
app_update 298740
quit";
public static void RunSteamCmd()
{
if (_steamCmdDone)
return;
var log = LogManager.GetLogger("SteamCMD");
if (!Directory.Exists(STEAMCMD_DIR))
{
Directory.CreateDirectory(STEAMCMD_DIR);
}
if (!File.Exists(RUNSCRIPT_PATH))
File.WriteAllText(RUNSCRIPT_PATH, RUNSCRIPT);
if (!File.Exists(STEAMCMD_PATH))
{
try
{
log.Info("Downloading SteamCMD.");
using (var client = new WebClient())
client.DownloadFile("https://steamcdn-a.akamaihd.net/client/installer/steamcmd.zip", STEAMCMD_ZIP);
ZipFile.ExtractToDirectory(STEAMCMD_ZIP, STEAMCMD_DIR);
File.Delete(STEAMCMD_ZIP);
log.Info("SteamCMD downloaded successfully!");
}
catch
{
log.Error("Failed to download SteamCMD, unable to update the DS.");
return;
}
}
log.Info("Checking for DS updates.");
var steamCmdProc = new ProcessStartInfo(STEAMCMD_PATH, "+runscript runscript.txt")
{
WorkingDirectory = Path.Combine(Directory.GetCurrentDirectory(), STEAMCMD_DIR),
UseShellExecute = false,
RedirectStandardOutput = true,
StandardOutputEncoding = Encoding.ASCII
};
var cmd = Process.Start(steamCmdProc);
// ReSharper disable once PossibleNullReferenceException
while (!cmd.HasExited)
{
log.Info(cmd.StandardOutput.ReadLine());
Thread.Sleep(100);
}
_steamCmdDone = true;
}
public static void RunServer(TorchConfig config)
{
/*
if (!parser.ParseArguments(args, config))
{
_log.Error($"Parsing arguments failed: {string.Join(" ", args)}");
return;
}
if (!string.IsNullOrEmpty(config.Config) && File.Exists(config.Config))
{
config = ServerConfig.LoadFrom(config.Config);
parser.ParseArguments(args, config);
}*/
//RestartOnCrash autostart autosave=15
//gamepath ="C:\Program Files\Space Engineers DS" instance="Hydro Survival" instancepath="C:\ProgramData\SpaceEngineersDedicated\Hydro Survival"
/*
if (config.InstallService)
{
var serviceName = $"\"Torch - {config.InstanceName}\"";
// Working on installing the service properly instead of with sc.exe
_log.Info($"Installing service '{serviceName}");
var exePath = $"\"{Assembly.GetExecutingAssembly().Location}\"";
var createInfo = new ServiceCreateInfo
{
Name = config.InstanceName,
BinaryPath = exePath,
};
_log.Info("Service Installed");
var runArgs = string.Join(" ", args.Skip(1));
_log.Info($"Installing Torch as a service with arguments '{runArgs}'");
var startInfo = new ProcessStartInfo
{
FileName = "sc.exe",
Arguments = $"create Torch binPath=\"{Assembly.GetExecutingAssembly().Location} {runArgs}\"",
CreateNoWindow = true,
UseShellExecute = true,
Verb = "runas"
};
Process.Start(startInfo).WaitForExit();
_log.Info("Torch service installed");
return;
}
if (config.UninstallService)
{
_log.Info("Uninstalling Torch service");
var startInfo = new ProcessStartInfo
{
FileName = "sc.exe",
Arguments = "delete Torch",
CreateNoWindow = true,
UseShellExecute = true,
Verb = "runas"
};
Process.Start(startInfo).WaitForExit();
_log.Info("Torch service uninstalled");
return;
}*/
_server = new TorchServer(config);
_server.Init();
if (config.NoGui || config.Autostart)
{
new Thread(() => _server.Start()).Start();
}
if (!config.NoGui)
{
var ui = new TorchUI((TorchServer)_server);
ui.ShowDialog();
}
}
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
var basePath = Path.Combine(Path.GetDirectoryName(typeof(Program).Assembly.Location), "DedicatedServer64");
string asmPath = Path.Combine(basePath, new AssemblyName(args.Name).Name + ".dll");
if (File.Exists(asmPath))
return Assembly.LoadFrom(asmPath);
}
catch
{
// ignored
}
return null;
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = (Exception)e.ExceptionObject;
_log.Fatal(ex);
Console.WriteLine("Exiting in 5 seconds.");
Thread.Sleep(5000);
if (_restartOnCrash)
{
var exe = typeof(Program).Assembly.Location;
_config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
Process.Start(exe, _config.ToString());
}
//1627 = Function failed during execution.
Environment.Exit(1627);
} }
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,4 +1,17 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyVersion("1.1.207.7")] [assembly: AssemblyTitle("Torch Server")]
[assembly: AssemblyFileVersion("1.1.207.7")] [assembly: AssemblyDescription("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Torch")]
[assembly: AssemblyCopyright("Copyright © Torch API 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

View File

@@ -1,16 +0,0 @@
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
using System.Reflection;
<# var dt = DateTime.Now;
int major = 1;
int minor = 1;
int build = dt.DayOfYear;
int rev = (int)dt.TimeOfDay.TotalMinutes / 2;
#>
[assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]
[assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= build #>.<#= rev #>")]

View File

@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Media;
namespace Torch.Server
{
public class RichTextBoxWriter : TextWriter
{
private RichTextBox textbox;
private StringBuilder _cache = new StringBuilder();
public RichTextBoxWriter(RichTextBox textbox)
{
this.textbox = textbox;
textbox.Document.Background = new SolidColorBrush(UnpackColor(Console.BackgroundColor));
textbox.Document.Blocks.Clear();
textbox.Document.Blocks.Add(new Paragraph {LineHeight = 12});
}
public override void Write(char value)
{
if (value == '\r')
return;
_cache.Append(value);
if (value == '\n')
{
var str = _cache.ToString();
_cache.Clear();
var brush = _brushes[Console.ForegroundColor];
textbox.Dispatcher.BeginInvoke(() =>
{
var p = (Paragraph)textbox.Document.Blocks.FirstBlock;
p.Inlines.Add(new Run(str) { Foreground = brush });
textbox.ScrollToEnd();
});
}
}
public override void Write(string value)
{
var brush = _brushes[Console.ForegroundColor];
textbox.Dispatcher.BeginInvoke(() =>
{
var p = (Paragraph)textbox.Document.Blocks.FirstBlock;
p.Inlines.Add(new Run(value) { Foreground = brush });
textbox.ScrollToEnd();
});
}
public override Encoding Encoding
{
get { return Encoding.ASCII; }
}
static RichTextBoxWriter()
{
foreach (var value in (ConsoleColor[])Enum.GetValues(typeof(ConsoleColor)))
{
_brushes.Add(value, new SolidColorBrush(UnpackColor(value)));
}
}
private static Dictionary<ConsoleColor, SolidColorBrush> _brushes = new Dictionary<ConsoleColor, SolidColorBrush>();
private static Color UnpackColor(ConsoleColor color)
{
var colorByte = (byte)color;
var isBright = (colorByte & 0b1000) >> 3 > 0;
var brightness = isBright ? (byte)255 : (byte)128;
var red = (colorByte & 0b0100) >> 2;
var green = (colorByte & 0b0010) >> 1;
var blue = (colorByte & 0b0001);
return new Color
{
R = (byte)(brightness * red),
G = (byte)(brightness * green),
B = (byte)(brightness * blue),
A = 255
};
}
}
}

View File

@@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Torch.Collections;
namespace Torch.Server
{
public class ServerStatistics
{
public RollingAverage SimSpeed { get; } = new RollingAverage(30);
}
}

View File

@@ -0,0 +1,17 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Hyperlink" x:Name="LegalshtuffLink">
<Setter Property="NavigateUri" Value="https://github.com/MahApps/MahApps.Metro/blob/develop/LICENSE" />
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,85 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TabControl">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabControl">
<Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0"/>
<ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto"/>
<RowDefinition x:Name="RowDefinition1" Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="HeaderPanel" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1" Orientation="Horizontal"/>
<Border x:Name="ContentPanel" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
<TabPanel x:Name="HeaderPanel2"
Panel.ZIndex ="1"
KeyboardNavigation.TabIndex="1"
Grid.Column="0"
Grid.Row="0"
Margin="2,2,2,0"
IsItemsHost="true"/>
</ScrollViewer>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="TabStripPlacement" Value="Bottom">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="1"/>
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
<Setter Property="Margin" TargetName="HeaderPanel" Value="2,0,2,2"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Left">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0"/>
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="HeaderPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="ContentPanel" Value="1"/>
<Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
<Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
<Setter Property="Margin" TargetName="HeaderPanel" Value="2,2,0,2"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Right">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0"/>
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="HeaderPanel" Value="1"/>
<Setter Property="Grid.Column" TargetName="ContentPanel" Value="0"/>
<Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
<Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
<Setter Property="Margin" TargetName="HeaderPanel" Value="0,2,2,2"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Hyperlink" x:Name="LegalshtuffLink">
<Setter Property="NavigateUri" Value="https://github.com/MahApps/MahApps.Metro/blob/develop/LICENSE" />
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,19 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.AnimatedSingleRowTabControl.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="Hyperlink" x:Name="LegalshtuffLink">
<Setter Property="NavigateUri" Value="https://github.com/MahApps/MahApps.Metro/blob/develop/LICENSE" />
</Style>
</ResourceDictionary>

View File

@@ -0,0 +1,85 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
<!-- Accent and AppTheme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TabControl">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TabControl">
<Grid ClipToBounds="true" SnapsToDevicePixels="true" KeyboardNavigation.TabNavigation="Local">
<Grid.ColumnDefinitions>
<ColumnDefinition x:Name="ColumnDefinition0"/>
<ColumnDefinition x:Name="ColumnDefinition1" Width="0"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition x:Name="RowDefinition0" Height="Auto"/>
<RowDefinition x:Name="RowDefinition1" Height="*"/>
</Grid.RowDefinitions>
<StackPanel x:Name="HeaderPanel" Grid.Column="0" IsItemsHost="true" Margin="2,2,2,0" Grid.Row="0" KeyboardNavigation.TabIndex="1" Panel.ZIndex="1" Orientation="Horizontal"/>
<Border x:Name="ContentPanel" BorderBrush="Transparent" BorderThickness="{TemplateBinding BorderThickness}" Background="Transparent" Grid.Column="0" KeyboardNavigation.DirectionalNavigation="Contained" Grid.Row="1" KeyboardNavigation.TabIndex="2" KeyboardNavigation.TabNavigation="Local">
<ContentPresenter x:Name="PART_SelectedContentHost" ContentSource="SelectedContent" Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
</Border>
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Hidden">
<TabPanel x:Name="HeaderPanel2"
Panel.ZIndex ="1"
KeyboardNavigation.TabIndex="1"
Grid.Column="0"
Grid.Row="0"
Margin="2,2,2,0"
IsItemsHost="true"/>
</ScrollViewer>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="TabStripPlacement" Value="Bottom">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="1"/>
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="Auto"/>
<Setter Property="Margin" TargetName="HeaderPanel" Value="2,0,2,2"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Left">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0"/>
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="HeaderPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="ContentPanel" Value="1"/>
<Setter Property="Width" TargetName="ColumnDefinition0" Value="Auto"/>
<Setter Property="Width" TargetName="ColumnDefinition1" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
<Setter Property="Margin" TargetName="HeaderPanel" Value="2,2,0,2"/>
</Trigger>
<Trigger Property="TabStripPlacement" Value="Right">
<Setter Property="Grid.Row" TargetName="HeaderPanel" Value="0"/>
<Setter Property="Grid.Row" TargetName="ContentPanel" Value="0"/>
<Setter Property="Grid.Column" TargetName="HeaderPanel" Value="1"/>
<Setter Property="Grid.Column" TargetName="ContentPanel" Value="0"/>
<Setter Property="Width" TargetName="ColumnDefinition0" Value="*"/>
<Setter Property="Width" TargetName="ColumnDefinition1" Value="Auto"/>
<Setter Property="Height" TargetName="RowDefinition0" Value="*"/>
<Setter Property="Height" TargetName="RowDefinition1" Value="0"/>
<Setter Property="Margin" TargetName="HeaderPanel" Value="0,2,2,2"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Hyperlink" x:Name="LegalshtuffLink">
<Setter Property="NavigateUri" Value="https://github.com/MahApps/MahApps.Metro/blob/develop/LICENSE" />
</Style>
</ResourceDictionary>

View File

@@ -2,8 +2,6 @@
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}</ProjectGuid> <ProjectGuid>{CA50886B-7B22-4CD8-93A0-C06F38D4F77D}</ProjectGuid>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
@@ -15,10 +13,27 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath> <OutputPath>$(SolutionDir)\bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants> <DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType> <DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget> <PlatformTarget>x64</PlatformTarget>
@@ -27,7 +42,7 @@
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath> <OutputPath>$(SolutionDir)\bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants> <DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize> <Optimize>true</Optimize>
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
@@ -35,7 +50,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit> <Prefer32Bit>true</Prefer32Bit>
<DocumentationFile>bin\x64\Release\Torch.Server.xml</DocumentationFile> <DocumentationFile>$(SolutionDir)\bin\x64\Release\Torch.Server.xml</DocumentationFile>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>
<StartupObject>Torch.Server.Program</StartupObject> <StartupObject>Torch.Server.Program</StartupObject>
@@ -44,11 +59,17 @@
<ApplicationIcon>torchicon.ico</ApplicationIcon> <ApplicationIcon>torchicon.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ControlzEx, Version=3.0.2.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net45\ControlzEx.dll</HintPath>
</Reference>
<Reference Include="HavokWrapper, Version=1.0.6051.28726, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="HavokWrapper, Version=1.0.6051.28726, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\GameBinaries\HavokWrapper.dll</HintPath> <HintPath>..\GameBinaries\HavokWrapper.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="MahApps.Metro, Version=1.6.1.4, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MahApps.Metro.1.6.1\lib\net45\MahApps.Metro.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CodeAnalysis, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.CodeAnalysis, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\GameBinaries\Microsoft.CodeAnalysis.dll</HintPath> <HintPath>..\GameBinaries\Microsoft.CodeAnalysis.dll</HintPath>
@@ -63,7 +84,8 @@
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath> <HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference> </Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL"> <Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>..\packages\NLog.4.4.11\lib\net45\NLog.dll</HintPath> <HintPath>..\packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
<Private>True</Private>
</Reference> </Reference>
<Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Sandbox.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
@@ -95,18 +117,20 @@
<HintPath>..\GameBinaries\SpaceEngineers.ObjectBuilders.XmlSerializers.dll</HintPath> <HintPath>..\GameBinaries\SpaceEngineers.ObjectBuilders.XmlSerializers.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="SteamSDK, Version=0.0.0.0, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="Steamworks.NET">
<SpecificVersion>False</SpecificVersion> <HintPath>..\GameBinaries\Steamworks.NET.dll</HintPath>
<HintPath>..\GameBinaries\SteamSDK.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Configuration.Install" /> <Reference Include="System.Configuration.Install" />
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression.FileSystem" /> <Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.ServiceProcess" /> <Reference Include="System.ServiceProcess" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="System.Windows.Interactivity, Version=4.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\ControlzEx.3.0.2.4\lib\net45\System.Windows.Interactivity.dll</HintPath>
</Reference>
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@@ -124,6 +148,7 @@
<Reference Include="VRage.Audio, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="VRage.Audio, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\GameBinaries\VRage.Audio.dll</HintPath> <HintPath>..\GameBinaries\VRage.Audio.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="VRage.Dedicated, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64"> <Reference Include="VRage.Dedicated, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
@@ -180,20 +205,30 @@
<HintPath>..\GameBinaries\VRage.Scripting.dll</HintPath> <HintPath>..\GameBinaries\VRage.Scripting.dll</HintPath>
<Private>False</Private> <Private>False</Private>
</Reference> </Reference>
<Reference Include="VRage.Steam">
<HintPath>..\GameBinaries\VRage.Steam.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Managers\InstanceManager.cs" /> <Compile Include="..\Versioning\AssemblyVersion.cs">
<Compile Include="NativeMethods.cs" /> <Link>Properties\AssemblyVersion.cs</Link>
<Compile Include="Properties\AssemblyInfo.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>AssemblyInfo.tt</DependentUpon>
</Compile> </Compile>
<Compile Include="Properties\AssemblyInfo1.cs" /> <Compile Include="Commands\WhitelistCommands.cs" />
<Compile Include="ServerStatistics.cs" /> <Compile Include="FlowDocumentTarget.cs" />
<Compile Include="ListBoxExtensions.cs" />
<Compile Include="Managers\EntityControlManager.cs" />
<Compile Include="Managers\MultiplayerManagerDedicated.cs" />
<Compile Include="Managers\InstanceManager.cs" />
<Compile Include="Managers\MultiplayerManagerDedicatedEventShim.cs" />
<Compile Include="Managers\MultiplayerManagerDedicatedPatchShim.cs" />
<Compile Include="NativeMethods.cs" />
<Compile Include="Initializer.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TorchConfig.cs" /> <Compile Include="TorchConfig.cs" />
<Compile Include="TorchService.cs"> <Compile Include="TorchService.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
@@ -202,11 +237,32 @@
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="ViewModels\BlockLimitViewModel.cs" /> <Compile Include="ViewModels\BlockLimitViewModel.cs" />
<Compile Include="ViewModels\CheckpointViewModel.cs" />
<Compile Include="ViewModels\Entities\Blocks\BlockViewModel.cs" /> <Compile Include="ViewModels\Entities\Blocks\BlockViewModel.cs" />
<Compile Include="ViewModels\Entities\Blocks\BlockViewModelGenerator.cs" /> <Compile Include="ViewModels\Entities\Blocks\BlockViewModelGenerator.cs" />
<Compile Include="ViewModels\Entities\Blocks\PropertyViewModel.cs" /> <Compile Include="ViewModels\Entities\Blocks\PropertyViewModel.cs" />
<Compile Include="ViewModels\Entities\CharacterViewModel.cs" /> <Compile Include="ViewModels\Entities\CharacterViewModel.cs" />
<Compile Include="ViewModels\ConfigDedicatedViewModel.cs" /> <Compile Include="ViewModels\ConfigDedicatedViewModel.cs" />
<Compile Include="ViewModels\Entities\EntityControlViewModel.cs" />
<Compile Include="ViewModels\SessionSettingsViewModel.cs" />
<Compile Include="Views\Converters\DefinitionToIdConverter.cs" />
<Compile Include="Views\Converters\BooleanAndConverter.cs" />
<Compile Include="Views\Converters\ListConverter.cs" />
<Compile Include="MultiTextWriter.cs" />
<Compile Include="RichTextBoxWriter.cs" />
<Compile Include="Views\Entities\CharacterView.xaml.cs">
<DependentUpon>CharacterView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ThemeControl.xaml.cs">
<DependentUpon>ThemeControl.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ValidationRules\ListConverterValidationRule.cs" />
<Compile Include="Views\Entities\EntityControlHost.xaml.cs">
<DependentUpon>EntityControlHost.xaml</DependentUpon>
</Compile>
<Compile Include="Views\Entities\EntityControlsView.xaml.cs">
<DependentUpon>EntityControlsView.xaml</DependentUpon>
</Compile>
<Compile Include="ViewModels\EntityTreeViewModel.cs" /> <Compile Include="ViewModels\EntityTreeViewModel.cs" />
<Compile Include="ViewModels\Entities\EntityViewModel.cs" /> <Compile Include="ViewModels\Entities\EntityViewModel.cs" />
<Compile Include="ViewModels\Entities\FloatingObjectViewModel.cs" /> <Compile Include="ViewModels\Entities\FloatingObjectViewModel.cs" />
@@ -214,7 +270,6 @@
<Compile Include="ViewModels\ILazyLoad.cs" /> <Compile Include="ViewModels\ILazyLoad.cs" />
<Compile Include="ViewModels\PluginManagerViewModel.cs" /> <Compile Include="ViewModels\PluginManagerViewModel.cs" />
<Compile Include="ViewModels\PluginViewModel.cs" /> <Compile Include="ViewModels\PluginViewModel.cs" />
<Compile Include="ViewModels\SessionSettingsViewModel.cs" />
<Compile Include="ViewModels\Entities\VoxelMapViewModel.cs" /> <Compile Include="ViewModels\Entities\VoxelMapViewModel.cs" />
<Compile Include="ViewModels\SteamUserViewModel.cs" /> <Compile Include="ViewModels\SteamUserViewModel.cs" />
<Compile Include="Views\AddWorkshopItemsDialog.xaml.cs"> <Compile Include="Views\AddWorkshopItemsDialog.xaml.cs">
@@ -245,15 +300,15 @@
<Compile Include="Views\Entities\VoxelMapView.xaml.cs"> <Compile Include="Views\Entities\VoxelMapView.xaml.cs">
<DependentUpon>VoxelMapView.xaml</DependentUpon> <DependentUpon>VoxelMapView.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\FirstTimeSetup.xaml.cs">
<DependentUpon>FirstTimeSetup.xaml</DependentUpon>
</Compile>
<Compile Include="Views\ModsControl.xaml.cs"> <Compile Include="Views\ModsControl.xaml.cs">
<DependentUpon>ModsControl.xaml</DependentUpon> <DependentUpon>ModsControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\PluginsControl.xaml.cs"> <Compile Include="Views\PluginsControl.xaml.cs">
<DependentUpon>PluginsControl.xaml</DependentUpon> <DependentUpon>PluginsControl.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Views\SessionSettingsView.xaml.cs">
<DependentUpon>SessionSettingsView.xaml</DependentUpon>
</Compile>
<Compile Include="Views\TorchUI.xaml.cs"> <Compile Include="Views\TorchUI.xaml.cs">
<DependentUpon>TorchUI.xaml</DependentUpon> <DependentUpon>TorchUI.xaml</DependentUpon>
</Compile> </Compile>
@@ -262,6 +317,10 @@
</Compile> </Compile>
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="TorchServer.cs" /> <Compile Include="TorchServer.cs" />
<Compile Include="Views\ValidationRules\NumberValidationRule.cs" />
<Compile Include="Views\WorldGeneratorDialog.xaml.cs">
<DependentUpon>WorldGeneratorDialog.xaml</DependentUpon>
</Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\Resources.Designer.cs"> <Compile Include="Properties\Resources.Designer.cs">
@@ -289,15 +348,39 @@
<ProjectReference Include="..\Torch.API\Torch.API.csproj"> <ProjectReference Include="..\Torch.API\Torch.API.csproj">
<Project>{fba5d932-6254-4a1e-baf4-e229fa94e3c2}</Project> <Project>{fba5d932-6254-4a1e-baf4-e229fa94e3c2}</Project>
<Name>Torch.API</Name> <Name>Torch.API</Name>
<Private>True</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\Torch\Torch.csproj"> <ProjectReference Include="..\Torch\Torch.csproj">
<Project>{7e01635c-3b67-472e-bcd6-c5539564f214}</Project> <Project>{7e01635c-3b67-472e-bcd6-c5539564f214}</Project>
<Name>Torch</Name> <Name>Torch</Name>
<Private>True</Private> <Private>False</Private>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Page Include="Themes\Dark Theme Animated.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\Dark Theme.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\Light Theme Animated.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Themes\Light Theme.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Entities\EntityControlHost.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Entities\EntityControlsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\AddWorkshopItemsDialog.xaml"> <Page Include="Views\AddWorkshopItemsDialog.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@@ -322,26 +405,38 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\Entities\CharacterView.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\Entities\GridView.xaml"> <Page Include="Views\Entities\GridView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\PluginsControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\Entities\VoxelMapView.xaml"> <Page Include="Views\Entities\VoxelMapView.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\FirstTimeSetup.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ModsControl.xaml"> <Page Include="Views\ModsControl.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\PluginsControl.xaml"> <Page Include="Views\Resources.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Views\SessionSettingsView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\ThemeControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Views\TorchUI.xaml"> <Page Include="Views\TorchUI.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@@ -350,6 +445,10 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</Page> </Page>
<Page Include="Views\WorldGeneratorDialog.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="torchicon.ico" /> <Resource Include="torchicon.ico" />
@@ -358,23 +457,20 @@
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" /> <Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="Properties\AssemblyInfo.tt"> <BootstrapperPackage Include=".NETFramework,Version=v4.6.1">
<Generator>TextTemplatingFileGenerator</Generator> <Visible>False</Visible>
<LastGenOutput>AssemblyInfo.cs</LastGenOutput> <ProductName>Microsoft .NET Framework 4.6.1 %28x86 and x64%29</ProductName>
</Content> <Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup> </ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\TransformOnBuild.targets" />
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>cd "$(TargetDir)" <PostBuildEvent>copy "$(SolutionDir)NLog.config" "$(TargetDir)"</PostBuildEvent>
copy "$(SolutionDir)NLog.config" "$(TargetDir)"
"Torch Server Release.bat"</PostBuildEvent>
</PropertyGroup> </PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project> </Project>

View File

@@ -8,6 +8,7 @@ using NLog;
namespace Torch.Server namespace Torch.Server
{ {
// TODO: redesign this gerbage
public class TorchConfig : CommandLine, ITorchConfig public class TorchConfig : CommandLine, ITorchConfig
{ {
private static Logger _log = LogManager.GetLogger("Config"); private static Logger _log = LogManager.GetLogger("Config");
@@ -59,8 +60,22 @@ namespace Torch.Server
/// <inheritdoc /> /// <inheritdoc />
public List<string> Plugins { get; set; } = new List<string>(); public List<string> Plugins { get; set; } = new List<string>();
public bool EnableWhitelist { get; set; } = false;
public HashSet<ulong> Whitelist { get; set; } = new HashSet<ulong>();
internal Point WindowSize { get; set; } = new Point(800, 600); internal Point WindowSize { get; set; } = new Point(800, 600);
internal Point WindowPosition { get; set; } = new Point(); internal Point WindowPosition { get; set; } = new Point();
public string LastUsedTheme { get; set; } = "Torch Theme";
//TODO: REMOVE ME BY JULY 2019
[Obsolete("Use vanilla reserved slot config")]
public HashSet<ulong> ReservedPlayers { get; set; } = new HashSet<ulong>();
//Prevent reserved players being written to disk, but allow it to bre read
//remove this when ReservedPlayers is removed
private bool ShouldSerializeReservedPlayers() => false;
[XmlIgnore] [XmlIgnore]
private string _path; private string _path;

View File

@@ -1,124 +1,108 @@
using Sandbox; #region
using Sandbox.Engine.Utils;
using Sandbox.Game;
using Sandbox.Game.World;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Net;
using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices; using System.Text;
using System.Security.Principal;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Xml.Serialization.GeneratedAssembly; using System.Windows.Forms;
using Sandbox.Engine.Analytics; using NLog;
using Sandbox;
using Sandbox.Engine.Networking;
using Sandbox.Game.Multiplayer; using Sandbox.Game.Multiplayer;
using Sandbox.ModAPI; using Sandbox.Game.World;
using SteamSDK;
using Torch.API; using Torch.API;
using Torch.Managers; using Torch.API.Managers;
using Torch.API.Session;
using Torch.Commands;
using Torch.Mod;
using Torch.Server.Commands;
using Torch.Server.Managers; using Torch.Server.Managers;
using Torch.Utils;
using VRage;
using VRage.Dedicated; using VRage.Dedicated;
using VRage.FileSystem; using VRage.Dedicated.RemoteAPI;
using VRage.Game; using VRage.GameServices;
using VRage.Game.ModAPI; using VRage.Steam;
using VRage.Game.ObjectBuilder; using Timer = System.Threading.Timer;
using VRage.Game.SessionComponents;
using VRage.Library; #endregion
using VRage.ObjectBuilders;
using VRage.Plugins;
using VRage.Utils;
#pragma warning disable 618 #pragma warning disable 618
namespace Torch.Server namespace Torch.Server
{ {
public class TorchServer : TorchBase, ITorchServer public class TorchServer : TorchBase, ITorchServer
{ {
//public MyConfigDedicated<MyObjectBuilder_SessionSettings> DedicatedConfig { get; set; } private bool _canRun;
public float SimulationRatio { get => _simRatio; set { _simRatio = value; OnPropertyChanged(); } }
public TimeSpan ElapsedPlayTime { get => _elapsedPlayTime; set { _elapsedPlayTime = value; OnPropertyChanged(); } }
public Thread GameThread { get; private set; }
public ServerState State { get => _state; private set { _state = value; OnPropertyChanged(); } }
public bool IsRunning { get => _isRunning; set { _isRunning = value; OnPropertyChanged(); } }
public InstanceManager DedicatedInstance { get; }
/// <inheritdoc />
public string InstanceName => Config?.InstanceName;
/// <inheritdoc />
public string InstancePath => Config?.InstancePath;
private bool _isRunning;
private ServerState _state;
private TimeSpan _elapsedPlayTime; private TimeSpan _elapsedPlayTime;
private bool _hasRun;
private bool _isRunning;
private float _simRatio; private float _simRatio;
private readonly AutoResetEvent _stopHandle = new AutoResetEvent(false); private ServerState _state;
private Timer _watchdog;
private Stopwatch _uptime; private Stopwatch _uptime;
private Timer _watchdog;
/// <inheritdoc />
public TorchServer(TorchConfig config = null) public TorchServer(TorchConfig config = null)
{ {
DedicatedInstance = new InstanceManager(this); DedicatedInstance = new InstanceManager(this);
AddManager(DedicatedInstance); AddManager(DedicatedInstance);
AddManager(new EntityControlManager(this));
Config = config ?? new TorchConfig(); Config = config ?? new TorchConfig();
MyFakes.ENABLE_INFINARIO = false;
var sessionManager = Managers.GetManager<ITorchSessionManager>();
sessionManager.AddFactory(x => new MultiplayerManagerDedicated(this));
} }
/// <inheritdoc />
public float SimulationRatio { get => _simRatio; set => SetValue(ref _simRatio, value); }
/// <inheritdoc />
public TimeSpan ElapsedPlayTime { get => _elapsedPlayTime; set => SetValue(ref _elapsedPlayTime, value); }
/// <inheritdoc />
public Thread GameThread { get; private set; }
/// <inheritdoc />
public bool IsRunning { get => _isRunning; set => SetValue(ref _isRunning, value); }
public bool CanRun { get => _canRun; set => SetValue(ref _canRun, value); }
/// <inheritdoc />
public InstanceManager DedicatedInstance { get; }
/// <inheritdoc />
public string InstanceName => Config?.InstanceName;
/// <inheritdoc />
protected override uint SteamAppId => 244850;
/// <inheritdoc />
protected override string SteamAppName => "SpaceEngineersDedicated";
/// <inheritdoc />
public ServerState State { get => _state; private set => SetValue(ref _state, value); }
public event Action<ITorchServer> Initialized;
/// <inheritdoc />
public string InstancePath => Config?.InstancePath;
/// <inheritdoc /> /// <inheritdoc />
public override void Init() public override void Init()
{ {
Log.Info($"Init server '{Config.InstanceName}' at '{Config.InstancePath}'"); Log.Info("Initializing server");
MySandboxGame.IsDedicated = true;
base.Init(); base.Init();
Managers.GetManager<ITorchSessionManager>().SessionStateChanged += OnSessionStateChanged;
MyPerGameSettings.SendLogToKeen = false; GetManager<InstanceManager>().LoadInstance(Config.InstancePath);
MyPerServerSettings.GameName = MyPerGameSettings.GameName; CanRun = true;
MyPerServerSettings.GameNameSafe = MyPerGameSettings.GameNameSafe; Initialized?.Invoke(this);
MyPerServerSettings.GameDSName = MyPerServerSettings.GameNameSafe + "Dedicated"; Log.Info($"Initialized server '{Config.InstanceName}' at '{Config.InstancePath}'");
MyPerServerSettings.GameDSDescription = "Your place for space engineering, destruction and exploring.";
MySessionComponentExtDebug.ForceDisable = true;
MyPerServerSettings.AppId = 244850;
MyFinalBuildConstants.APP_VERSION = MyPerGameSettings.BasicGameInfo.GameVersion;
MyObjectBuilderSerializer.RegisterFromAssembly(typeof(MyObjectBuilder_CheckpointSerializer).Assembly);
InvokeBeforeRun();
MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly);
MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly);
MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly);
MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly);
MyPlugins.Load();
MyGlobalTypeMetadata.Static.Init();
Plugins.LoadPlugins();
}
private void InvokeBeforeRun()
{
MySandboxGame.Log.Init("SpaceEngineers-Dedicated.log", MyFinalBuildConstants.APP_VERSION_STRING);
MySandboxGame.Log.WriteLine("Steam build: Always true");
MySandboxGame.Log.WriteLine("Environment.ProcessorCount: " + MyEnvironment.ProcessorCount);
//MySandboxGame.Log.WriteLine("Environment.OSVersion: " + GetOsName());
MySandboxGame.Log.WriteLine("Environment.CommandLine: " + Environment.CommandLine);
MySandboxGame.Log.WriteLine("Environment.Is64BitProcess: " + MyEnvironment.Is64BitProcess);
MySandboxGame.Log.WriteLine("Environment.Is64BitOperatingSystem: " + Environment.Is64BitOperatingSystem);
//MySandboxGame.Log.WriteLine("Environment.Version: " + GetNETFromRegistry());
MySandboxGame.Log.WriteLine("Environment.CurrentDirectory: " + Environment.CurrentDirectory);
MySandboxGame.Log.WriteLine("MainAssembly.ProcessorArchitecture: " + Assembly.GetExecutingAssembly().GetArchitecture());
MySandboxGame.Log.WriteLine("ExecutingAssembly.ProcessorArchitecture: " + MyFileSystem.MainAssembly.GetArchitecture());
MySandboxGame.Log.WriteLine("IntPtr.Size: " + IntPtr.Size);
MySandboxGame.Log.WriteLine("Default Culture: " + CultureInfo.CurrentCulture.Name);
MySandboxGame.Log.WriteLine("Default UI Culture: " + CultureInfo.CurrentUICulture.Name);
MySandboxGame.Log.WriteLine("IsAdmin: " + new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator));
MyLog.Default = MySandboxGame.Log;
Thread.CurrentThread.Name = "Main thread";
//Because we want exceptions from users to be in english
Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
MySandboxGame.Config = new MyConfig("SpaceEngineers-Dedicated.cfg");
MySandboxGame.Config.Load();
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -127,64 +111,26 @@ namespace Torch.Server
if (State != ServerState.Stopped) if (State != ServerState.Stopped)
return; return;
DedicatedInstance.SaveConfig(); if (_hasRun)
_uptime = Stopwatch.StartNew(); {
IsRunning = true; Restart();
GameThread = Thread.CurrentThread; return;
Config.Save(); }
State = ServerState.Starting; State = ServerState.Starting;
IsRunning = true;
CanRun = false;
_hasRun = true;
Log.Info("Starting server."); Log.Info("Starting server.");
MySandboxGame.ConfigDedicated = DedicatedInstance.DedicatedConfig.Model;
if (MySandboxGame.ConfigDedicated.RemoteApiEnabled && !string.IsNullOrEmpty(MySandboxGame.ConfigDedicated.RemoteSecurityKey))
{
var myRemoteServer = new MyRemoteServer(MySandboxGame.ConfigDedicated.RemoteApiPort, MySandboxGame.ConfigDedicated.RemoteSecurityKey);
Log.Info($"Remote API started on port {myRemoteServer.Port}");
}
var runInternal = typeof(DedicatedServer).GetMethod("RunInternal", BindingFlags.Static | BindingFlags.NonPublic); _uptime = Stopwatch.StartNew();
MySandboxGame.IsDedicated = true;
Environment.SetEnvironmentVariable("SteamAppId", MyPerServerSettings.AppId.ToString());
VRage.Service.ExitListenerSTA.OnExit += delegate { MySandboxGame.Static?.Exit(); };
base.Start(); base.Start();
runInternal.Invoke(null, null);
MySandboxGame.Log.Close();
State = ServerState.Stopped;
}
/// <inheritdoc />
public override void Init(object gameInstance)
{
base.Init(gameInstance);
State = ServerState.Running;
SteamServerAPI.Instance.GameServer.SetKeyValue("SM", "Torch");
}
/// <inheritdoc />
public override void Update()
{
base.Update();
SimulationRatio = Sync.ServerSimulationRatio;
var elapsed = TimeSpan.FromSeconds(Math.Floor(_uptime.Elapsed.TotalSeconds));
ElapsedPlayTime = elapsed;
if (_watchdog == null && Config.TickTimeout > 0)
{
Log.Info("Starting server watchdog.");
_watchdog = new Timer(CheckServerResponding, this, TimeSpan.Zero, TimeSpan.FromSeconds(Config.TickTimeout));
}
}
private static void CheckServerResponding(object state)
{
var mre = new ManualResetEvent(false);
((TorchServer)state).Invoke(() => mre.Set());
if (!mre.WaitOne(TimeSpan.FromSeconds(Instance.Config.TickTimeout)))
{
var mainThread = MySandboxGame.Static.UpdateThread;
mainThread.Suspend();
var stackTrace = new StackTrace(mainThread, true);
throw new TimeoutException($"Server watchdog detected that the server was frozen for at least {((TorchServer)state).Config.TickTimeout} seconds.\n{stackTrace}");
}
Log.Debug("Server watchdog responded");
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -192,71 +138,161 @@ namespace Torch.Server
{ {
if (State == ServerState.Stopped) if (State == ServerState.Stopped)
Log.Error("Server is already stopped"); Log.Error("Server is already stopped");
if (Thread.CurrentThread != MySandboxGame.Static.UpdateThread)
{
Log.Debug("Invoking server stop on game thread.");
Invoke(Stop);
return;
}
Log.Info("Stopping server."); Log.Info("Stopping server.");
base.Stop();
//Unload all the static junk.
//TODO: Finish unloading all server data so it's in a completely clean state.
MySandboxGame.Static.Exit();
Log.Info("Server stopped."); Log.Info("Server stopped.");
_stopHandle.Set();
State = ServerState.Stopped; State = ServerState.Stopped;
IsRunning = false; IsRunning = false;
CanRun = true;
} }
/// <summary> /// <summary>
/// Restart the program. DOES NOT SAVE! /// Restart the program.
/// </summary> /// </summary>
public override void Restart() public override void Restart()
{ {
var exe = Assembly.GetExecutingAssembly().Location; if (IsRunning)
((TorchConfig)Config).WaitForPID = Process.GetCurrentProcess().Id.ToString(); Save().ContinueWith(DoRestart, this, TaskContinuationOptions.RunContinuationsAsynchronously);
Process.Start(exe, Config.ToString()); else
Environment.Exit(0); DoRestart(null, this);
void DoRestart(Task<GameSaveResult> task, object torch0)
{
var torch = (TorchServer)torch0;
torch.Stop();
// TODO clone this
var config = (TorchConfig)torch.Config;
LogManager.Flush();
string exe = Assembly.GetExecutingAssembly().Location;
Debug.Assert(exe != null);
config.WaitForPID = Process.GetCurrentProcess().Id.ToString();
config.Autostart = true;
Process.Start(exe, config.ToString());
Process.GetCurrentProcess().Kill();
}
} }
/// <inheritdoc/> private void OnSessionStateChanged(ITorchSession session, TorchSessionState newState)
public override Task Save(long callerId)
{ {
return SaveGameAsync(statusCode => SaveCompleted(statusCode, callerId)); if (newState == TorchSessionState.Unloading || newState == TorchSessionState.Unloaded)
{
_watchdog?.Dispose();
_watchdog = null;
ModCommunication.Unregister();
} }
/// <summary> if (newState == TorchSessionState.Loaded)
/// Callback for when save has finished.
/// </summary>
/// <param name="statusCode">Return code of the save operation</param>
/// <param name="callerId">Caller of the save operation</param>
private void SaveCompleted(SaveGameStatus statusCode, long callerId = 0)
{ {
switch (statusCode) CurrentSession.Managers.GetManager<CommandManager>().RegisterCommandModule(typeof(WhitelistCommands));
{ ModCommunication.Register();
case SaveGameStatus.Success:
Log.Info("Save completed.");
Multiplayer.SendMessage("Saved game.", playerId: callerId);
break;
case SaveGameStatus.SaveInProgress:
Log.Error("Save failed, a save is already in progress.");
Multiplayer.SendMessage("Save failed, a save is already in progress.", playerId: callerId, font: MyFontEnum.Red);
break;
case SaveGameStatus.GameNotReady:
Log.Error("Save failed, game was not ready.");
Multiplayer.SendMessage("Save failed, game was not ready.", playerId: callerId, font: MyFontEnum.Red);
break;
case SaveGameStatus.TimedOut:
Log.Error("Save failed, save timed out.");
Multiplayer.SendMessage("Save failed, save timed out.", playerId: callerId, font: MyFontEnum.Red);
break;
default:
break;
} }
} }
/// <inheritdoc />
public override void Init(object gameInstance)
{
base.Init(gameInstance);
var game = gameInstance as MySandboxGame;
if (game != null && MySession.Static != null)
State = ServerState.Running;
else
State = ServerState.Stopped;
}
/// <inheritdoc />
public override void Update()
{
base.Update();
// Stops 1.00-1.02 flicker.
SimulationRatio = Math.Min(Sync.ServerSimulationRatio, 1);
var elapsed = TimeSpan.FromSeconds(Math.Floor(_uptime.Elapsed.TotalSeconds));
ElapsedPlayTime = elapsed;
if (_watchdog == null && Config.TickTimeout > 0)
{
Log.Info("Starting server watchdog.");
_watchdog = new Timer(CheckServerResponding, this, TimeSpan.Zero,
TimeSpan.FromSeconds(Config.TickTimeout));
}
}
#region Freeze Detection
private static void CheckServerResponding(object state)
{
var mre = new ManualResetEvent(false);
((TorchServer)state).Invoke(() => mre.Set());
if (!mre.WaitOne(TimeSpan.FromSeconds(Instance.Config.TickTimeout)))
{
#if DEBUG
Log.Error(
$"Server watchdog detected that the server was frozen for at least {((TorchServer) state).Config.TickTimeout} seconds.");
Log.Error(DumpFrozenThread(MySandboxGame.Static.UpdateThread));
#else
Log.Error(DumpFrozenThread(MySandboxGame.Static.UpdateThread));
throw new TimeoutException($"Server watchdog detected that the server was frozen for at least {((TorchServer)state).Config.TickTimeout} seconds.");
#endif
}
Log.Debug("Server watchdog responded");
}
private static string DumpFrozenThread(Thread thread, int traces = 3, int pause = 5000)
{
var stacks = new List<string>(traces);
var totalSize = 0;
for (var i = 0; i < traces; i++)
{
string dump = DumpStack(thread).ToString();
totalSize += dump.Length;
stacks.Add(dump);
Thread.Sleep(pause);
}
string commonPrefix = StringUtils.CommonSuffix(stacks);
// Advance prefix to include the line terminator.
commonPrefix = commonPrefix.Substring(commonPrefix.IndexOf('\n') + 1);
var result = new StringBuilder(totalSize - (stacks.Count - 1) * commonPrefix.Length);
result.AppendLine($"Frozen thread dump {thread.Name}");
result.AppendLine("Common prefix:").AppendLine(commonPrefix);
for (var i = 0; i < stacks.Count; i++)
if (stacks[i].Length > commonPrefix.Length)
{
result.AppendLine($"Suffix {i}");
result.AppendLine(stacks[i].Substring(0, stacks[i].Length - commonPrefix.Length));
}
return result.ToString();
}
private static StackTrace DumpStack(Thread thread)
{
try
{
thread.Suspend();
}
catch
{
// ignored
}
var stack = new StackTrace(thread, true);
try
{
thread.Resume();
}
catch
{
// ignored
}
return stack;
}
#endregion
} }
} }

View File

@@ -14,13 +14,15 @@ namespace Torch.Server
{ {
public const string Name = "Torch (SEDS)"; public const string Name = "Torch (SEDS)";
private TorchServer _server; private TorchServer _server;
private static Logger _log = LogManager.GetLogger("Torch"); private Initializer _initializer;
public TorchService() public TorchService()
{ {
ServiceName = Name; var workingDir = new FileInfo(typeof(TorchService).Assembly.Location).Directory.ToString();
Directory.SetCurrentDirectory(workingDir);
_initializer = new Initializer(workingDir);
CanHandlePowerEvent = true; ServiceName = Name;
CanHandleSessionChangeEvent = false; CanHandleSessionChangeEvent = false;
CanPauseAndContinue = false; CanPauseAndContinue = false;
CanStop = true; CanStop = true;
@@ -31,17 +33,8 @@ namespace Torch.Server
{ {
base.OnStart(args); base.OnStart(args);
string configName = args.Length > 0 ? args[0] : "TorchConfig.xml"; _initializer.Initialize(args);
var options = new TorchConfig("Torch"); _initializer.Run();
if (File.Exists(configName))
options = TorchConfig.LoadFrom(configName);
else
options.Save(configName);
_server = new TorchServer(options);
_server.Init();
_server.RunArgs = args;
Task.Run(() => _server.Start());
} }
/// <inheritdoc /> /// <inheritdoc />
@@ -50,17 +43,5 @@ namespace Torch.Server
_server.Stop(); _server.Stop();
base.OnStop(); base.OnStop();
} }
/// <inheritdoc />
protected override void OnShutdown()
{
base.OnShutdown();
}
/// <inheritdoc />
protected override bool OnPowerEvent(PowerBroadcastStatus powerStatus)
{
return base.OnPowerEvent(powerStatus);
}
} }
} }

View File

@@ -0,0 +1,132 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Torch.Collections;
using VRage;
using VRage.Game;
using VRage.Game.ModAPI;
using VRage.ObjectBuilders;
using VRage.Serialization;
using VRageMath;
namespace Torch.Server.ViewModels
{
public class CheckpointViewModel : ViewModel
{
private MyObjectBuilder_Checkpoint _checkpoint;
private SessionSettingsViewModel _sessionSettings;
public CheckpointViewModel(MyObjectBuilder_Checkpoint checkpoint)
{
_checkpoint = checkpoint;
_sessionSettings = new SessionSettingsViewModel(_checkpoint.Settings);
}
public static implicit operator MyObjectBuilder_Checkpoint(CheckpointViewModel model)
{
return model._checkpoint;
}
public Vector3I CurrentSector { get => _checkpoint.CurrentSector; set => SetValue(ref _checkpoint.CurrentSector, value); }
public long ElapsedGameTime { get => _checkpoint.ElapsedGameTime; set => SetValue(ref _checkpoint.ElapsedGameTime, value); }
public string SessionName { get => _checkpoint.SessionName; set => SetValue(ref _checkpoint.SessionName, value); }
public MyPositionAndOrientation SpectatorPosition { get => _checkpoint.SpectatorPosition; set => SetValue(ref _checkpoint.SpectatorPosition, value); }
public bool SpectatorIsLightOn { get => _checkpoint.SpectatorIsLightOn; set => SetValue(ref _checkpoint.SpectatorIsLightOn, value); }
public MyCameraControllerEnum CameraController { get => _checkpoint.CameraController; set => SetValue(ref _checkpoint.CameraController, value); }
public long CameraEntity { get => _checkpoint.CameraEntity; set => SetValue(ref _checkpoint.CameraEntity, value); }
public long ControlledObject { get => _checkpoint.ControlledObject; set => SetValue(ref _checkpoint.ControlledObject, value); }
public string Password { get => _checkpoint.Password; set => SetValue(ref _checkpoint.Password, value); }
public string Description { get => _checkpoint.Description; set => SetValue(ref _checkpoint.Description, value); }
public DateTime LastSaveTime { get => _checkpoint.LastSaveTime; set => SetValue(ref _checkpoint.LastSaveTime, value); }
public float SpectatorDistance { get => _checkpoint.SpectatorDistance; set => SetValue(ref _checkpoint.SpectatorDistance, value); }
public ulong? WorkshopId { get => _checkpoint.WorkshopId; set => SetValue(ref _checkpoint.WorkshopId, value); }
public MyObjectBuilder_Toolbar CharacterToolbar { get => _checkpoint.CharacterToolbar; set => SetValue(ref _checkpoint.CharacterToolbar, value); }
public SerializableDictionary<long, MyObjectBuilder_Checkpoint.PlayerId> ControlledEntities { get => _checkpoint.ControlledEntities; set => SetValue(ref _checkpoint.ControlledEntities, value); }
public SessionSettingsViewModel Settings
{
get => _sessionSettings;
set
{
SetValue(ref _sessionSettings, value);
_checkpoint.Settings = _sessionSettings;
}
}
public MyObjectBuilder_ScriptManager ScriptManagerData => throw new NotImplementedException();
public int AppVersion { get => _checkpoint.AppVersion; set => SetValue(ref _checkpoint.AppVersion, value); }
public MyObjectBuilder_FactionCollection Factions => throw new NotImplementedException();
public List<MyObjectBuilder_Checkpoint.ModItem> Mods { get => _checkpoint.Mods; set => SetValue(ref _checkpoint.Mods, value); }
public SerializableDictionary<ulong, MyPromoteLevel> PromotedUsers { get => _checkpoint.PromotedUsers; set => SetValue(ref _checkpoint.PromotedUsers, value); }
public HashSet<ulong> CreativeTools { get => _checkpoint.CreativeTools; set => SetValue(ref _checkpoint.CreativeTools, value); }
public SerializableDefinitionId Scenario { get => _checkpoint.Scenario; set => SetValue(ref _checkpoint.Scenario, value); }
public List<MyObjectBuilder_Checkpoint.RespawnCooldownItem> RespawnCooldowns { get => _checkpoint.RespawnCooldowns; set => SetValue(ref _checkpoint.RespawnCooldowns, value); }
public List<MyObjectBuilder_Identity> Identities { get => _checkpoint.Identities; set => SetValue(ref _checkpoint.Identities, value); }
public List<MyObjectBuilder_Client> Clients { get => _checkpoint.Clients; set => SetValue(ref _checkpoint.Clients, value); }
public MyEnvironmentHostilityEnum? PreviousEnvironmentHostility { get => _checkpoint.PreviousEnvironmentHostility; set => SetValue(ref _checkpoint.PreviousEnvironmentHostility, value); }
public SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, MyObjectBuilder_Player> AllPlayersData { get => _checkpoint.AllPlayersData; set => SetValue(ref _checkpoint.AllPlayersData, value); }
public SerializableDictionary<MyObjectBuilder_Checkpoint.PlayerId, List<Vector3>> AllPlayersColors { get => _checkpoint.AllPlayersColors; set => SetValue(ref _checkpoint.AllPlayersColors, value); }
public List<MyObjectBuilder_ChatHistory> ChatHistory { get => _checkpoint.ChatHistory; set => SetValue(ref _checkpoint.ChatHistory, value); }
public List<MyObjectBuilder_FactionChatHistory> FactionChatHistory { get => _checkpoint.FactionChatHistory; set => SetValue(ref _checkpoint.FactionChatHistory, value); }
public List<long> NonPlayerIdentities { get => _checkpoint.NonPlayerIdentities; set => SetValue(ref _checkpoint.NonPlayerIdentities, value); }
public SerializableDictionary<long, MyObjectBuilder_Gps> Gps { get => _checkpoint.Gps; set => SetValue(ref _checkpoint.Gps, value); }
public SerializableBoundingBoxD? WorldBoundaries { get => _checkpoint.WorldBoundaries; set => SetValue(ref _checkpoint.WorldBoundaries, value); }
public List<MyObjectBuilder_SessionComponent> SessionComponents { get => _checkpoint.SessionComponents; set => SetValue(ref _checkpoint.SessionComponents, value); }
public SerializableDefinitionId GameDefinition { get => _checkpoint.GameDefinition; set => SetValue(ref _checkpoint.GameDefinition, value); }
public HashSet<string> SessionComponentEnabled { get => _checkpoint.SessionComponentEnabled; set => SetValue(ref _checkpoint.SessionComponentEnabled, value); }
public HashSet<string> SessionComponentDisabled { get => _checkpoint.SessionComponentDisabled; set => SetValue(ref _checkpoint.SessionComponentDisabled, value); }
public DateTime InGameTime { get => _checkpoint.InGameTime; set => SetValue(ref _checkpoint.InGameTime, value); }
public MyObjectBuilder_SessionComponentMission MissionTriggers { get => _checkpoint.MissionTriggers; set => SetValue(ref _checkpoint.MissionTriggers, value); }
public string Briefing { get => _checkpoint.Briefing; set => SetValue(ref _checkpoint.Briefing, value); }
public string BriefingVideo { get => _checkpoint.BriefingVideo; set => SetValue(ref _checkpoint.BriefingVideo, value); }
public string CustomLoadingScreenImage { get => _checkpoint.CustomLoadingScreenImage; set => SetValue(ref _checkpoint.BriefingVideo, value); }
public string CustomLoadingScreenText { get => _checkpoint.CustomLoadingScreenText; set => SetValue(ref _checkpoint.CustomLoadingScreenText, value); }
public string CustomSkybox { get => _checkpoint.CustomSkybox; set => SetValue(ref _checkpoint.CustomSkybox, value); }
public int RequiresDX { get => _checkpoint.RequiresDX; set => SetValue(ref _checkpoint.RequiresDX, value); }
}
}

View File

@@ -6,6 +6,8 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using NLog; using NLog;
using Sandbox.Engine.Utils; using Sandbox.Engine.Utils;
using Torch.Collections;
using Torch.Server.Managers;
using VRage.Game; using VRage.Game;
using VRage.Game.ModAPI; using VRage.Game.ModAPI;
@@ -13,7 +15,7 @@ namespace Torch.Server.ViewModels
{ {
public class ConfigDedicatedViewModel : ViewModel public class ConfigDedicatedViewModel : ViewModel
{ {
private static readonly Logger Log = LogManager.GetLogger("Config"); private static readonly Logger Log = LogManager.GetCurrentClassLogger();
private MyConfigDedicated<MyObjectBuilder_SessionSettings> _config; private MyConfigDedicated<MyObjectBuilder_SessionSettings> _config;
public MyConfigDedicated<MyObjectBuilder_SessionSettings> Model => _config; public MyConfigDedicated<MyObjectBuilder_SessionSettings> Model => _config;
@@ -25,111 +27,110 @@ namespace Torch.Server.ViewModels
public ConfigDedicatedViewModel(MyConfigDedicated<MyObjectBuilder_SessionSettings> configDedicated) public ConfigDedicatedViewModel(MyConfigDedicated<MyObjectBuilder_SessionSettings> configDedicated)
{ {
_config = configDedicated; _config = configDedicated;
_config.IgnoreLastSession = true;
SessionSettings = new SessionSettingsViewModel(_config.SessionSettings); SessionSettings = new SessionSettingsViewModel(_config.SessionSettings);
Administrators = string.Join(Environment.NewLine, _config.Administrators);
Banned = string.Join(Environment.NewLine, _config.Banned);
Mods = string.Join(Environment.NewLine, _config.Mods);
} }
public void Save(string path = null) public void Save(string path = null)
{ {
var newline = new [] {Environment.NewLine}; Validate();
_config.Administrators.Clear(); _config.SessionSettings = _sessionSettings;
foreach (var admin in Administrators.Split(newline, StringSplitOptions.RemoveEmptyEntries)) // Never ever
_config.Administrators.Add(admin); _config.IgnoreLastSession = true;
_config.Save(path);
_config.Banned.Clear();
foreach (var banned in Banned.Split(newline, StringSplitOptions.RemoveEmptyEntries))
_config.Banned.Add(ulong.Parse(banned));
_config.Mods.Clear();
foreach (var mod in Mods.Split(newline, StringSplitOptions.RemoveEmptyEntries))
{
if (ulong.TryParse(mod, out ulong modId))
_config.Mods.Add(modId);
else
Log.Warn($"'{mod}' is not a valid mod ID.");
} }
_config.Save(path); public bool Validate()
{
if (SelectedWorld == null)
{
Log.Warn($"{nameof(SelectedWorld)} == null");
return false;
}
if (LoadWorld == null)
{
Log.Warn($"{nameof(LoadWorld)} == null");
return false;
}
return true;
} }
private SessionSettingsViewModel _sessionSettings; private SessionSettingsViewModel _sessionSettings;
public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } } public SessionSettingsViewModel SessionSettings { get => _sessionSettings; set { _sessionSettings = value; OnPropertyChanged(); } }
public ObservableList<string> WorldPaths { get; } = new ObservableList<string>(); public MtObservableList<WorldViewModel> Worlds { get; } = new MtObservableList<WorldViewModel>();
private string _administrators; private WorldViewModel _selectedWorld;
public string Administrators { get => _administrators; set { _administrators = value; OnPropertyChanged(); } } public WorldViewModel SelectedWorld
private string _banned;
public string Banned { get => _banned; set { _banned = value; OnPropertyChanged(); } }
private string _mods;
public string Mods { get => _mods; set { _mods = value; OnPropertyChanged(); } }
public int AsteroidAmount
{ {
get { return _config.AsteroidAmount; } get => _selectedWorld;
set { _config.AsteroidAmount = value; OnPropertyChanged(); } set
{
SetValue(ref _selectedWorld, value);
LoadWorld = _selectedWorld?.WorldPath;
}
} }
public ulong GroupId public List<string> Administrators { get => _config.Administrators; set => SetValue(x => _config.Administrators = x, value); }
{
get { return _config.GroupID; }
set { _config.GroupID = value; OnPropertyChanged(); }
}
public bool IgnoreLastSession public List<ulong> Banned { get => _config.Banned; set => SetValue(x => _config.Banned = x, value); }
{
get { return _config.IgnoreLastSession; }
set { _config.IgnoreLastSession = value; OnPropertyChanged(); }
}
public string IP public List<ulong> Reserved { get => _config.Reserved; set => SetValue(x => _config.Reserved = x, value); }
{
get { return _config.IP; }
set { _config.IP = value; OnPropertyChanged(); }
}
public int Port private List<ulong> _mods = new List<ulong>();
{ public List<ulong> Mods { get => _mods; set => SetValue(x => _mods = x, value); }
get { return _config.ServerPort; }
set { _config.ServerPort = value; OnPropertyChanged(); }
}
public string ServerName public int AsteroidAmount { get => _config.AsteroidAmount; set => SetValue(x => _config.AsteroidAmount = x, value); }
{
get { return _config.ServerName; }
set { _config.ServerName = value; OnPropertyChanged(); }
}
public bool PauseGameWhenEmpty public ulong GroupId { get => _config.GroupID; set => SetValue(x => _config.GroupID = x, value); }
{
get { return _config.PauseGameWhenEmpty; }
set { _config.PauseGameWhenEmpty = value; OnPropertyChanged(); }
}
public string PremadeCheckpointPath public string IP { get => _config.IP; set => SetValue(x => _config.IP = x, value); }
{
get { return _config.PremadeCheckpointPath; }
set { _config.PremadeCheckpointPath = value; OnPropertyChanged(); }
}
public string LoadWorld public int Port { get => _config.ServerPort; set => SetValue(x => _config.ServerPort = x, value); }
{
get { return _config.LoadWorld; }
set { _config.LoadWorld = value; OnPropertyChanged(); }
}
public int SteamPort public string ServerName { get => _config.ServerName; set => SetValue(x => _config.ServerName = x, value); }
{
get { return _config.SteamPort; }
set { _config.SteamPort = value; OnPropertyChanged(); }
}
public string WorldName public string ServerDescription { get => _config.ServerDescription; set => SetValue(x => _config.ServerDescription = x, value); }
public bool PauseGameWhenEmpty { get => _config.PauseGameWhenEmpty; set => SetValue(x => _config.PauseGameWhenEmpty = x, value); }
public bool AutodetectDependencies { get => _config.AutodetectDependencies; set => SetValue(x => _config.AutodetectDependencies = x, value); }
public string PremadeCheckpointPath { get => _config.PremadeCheckpointPath; set => SetValue(x => _config.PremadeCheckpointPath = x, value); }
public string LoadWorld { get => _config.LoadWorld; set => SetValue(x => _config.LoadWorld = x, value); }
public int SteamPort { get => _config.SteamPort; set => SetValue(x => _config.SteamPort = x, value); }
public string WorldName { get => _config.WorldName; set => SetValue(x => _config.WorldName = x, value); }
//this is a damn server password. I don't care if this is insecure. Bite me.
private string _password;
public string Password
{ {
get { return _config.WorldName; } get
set { _config.WorldName = value; OnPropertyChanged(); } {
if (string.IsNullOrEmpty(_password))
{
if (string.IsNullOrEmpty(_config.ServerPasswordHash))
return string.Empty;
return "**********";
}
return _password;
}
set
{
_password = value;
if(!string.IsNullOrEmpty(value))
_config.SetPassword(value);
else
{
_config.ServerPasswordHash = null;
_config.ServerPasswordSalt = null;
}
}
} }
} }
} }

View File

@@ -8,16 +8,17 @@ using System.Threading.Tasks;
using Sandbox.Game.Entities.Cube; using Sandbox.Game.Entities.Cube;
using Sandbox.ModAPI; using Sandbox.ModAPI;
using Sandbox.ModAPI.Interfaces; using Sandbox.ModAPI.Interfaces;
using Torch.Collections;
using Torch.Server.ViewModels.Entities; using Torch.Server.ViewModels.Entities;
namespace Torch.Server.ViewModels.Blocks namespace Torch.Server.ViewModels.Blocks
{ {
public class BlockViewModel : EntityViewModel public class BlockViewModel : EntityViewModel
{ {
public IMyTerminalBlock Block { get; } public IMyTerminalBlock Block => (IMyTerminalBlock) Entity;
public ObservableList<PropertyViewModel> Properties { get; } = new ObservableList<PropertyViewModel>(); public MtObservableList<PropertyViewModel> Properties { get; } = new MtObservableList<PropertyViewModel>();
public string FullName => $"{Block.CubeGrid.CustomName} - {Block.CustomName}"; public string FullName => $"{Block?.CubeGrid.CustomName} - {Block?.CustomName}";
public override string Name public override string Name
{ {
@@ -37,7 +38,7 @@ namespace Torch.Server.ViewModels.Blocks
public long BuiltBy public long BuiltBy
{ {
get => ((MySlimBlock)Block.SlimBlock).BuiltBy; get => ((MySlimBlock)Block?.SlimBlock)?.BuiltBy ?? 0;
set set
{ {
TorchBase.Instance.Invoke(() => TorchBase.Instance.Invoke(() =>
@@ -58,7 +59,6 @@ namespace Torch.Server.ViewModels.Blocks
public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree) public BlockViewModel(IMyTerminalBlock block, EntityTreeViewModel tree) : base(block, tree)
{ {
Block = block;
if (Block == null) if (Block == null)
return; return;

View File

@@ -6,7 +6,12 @@ namespace Torch.Server.ViewModels.Entities
{ {
public CharacterViewModel(MyCharacter character, EntityTreeViewModel tree) : base(character, tree) public CharacterViewModel(MyCharacter character, EntityTreeViewModel tree) : base(character, tree)
{ {
character.ControllerInfo.ControlAcquired += (x) => { OnPropertyChanged(nameof(Name)); };
character.ControllerInfo.ControlReleased += (x) => { OnPropertyChanged(nameof(Name)); };
}
public CharacterViewModel()
{
} }
} }
} }

View File

@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Torch.Server.ViewModels.Entities
{
public class EntityControlViewModel : ViewModel
{
internal const string SignalPropertyInvalidateControl =
"InvalidateControl-4124a476-704f-4762-8b5e-336a18e2f7e5";
internal void InvalidateControl()
{
// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(SignalPropertyInvalidateControl);
}
private bool _hide;
/// <summary>
/// Should this element be forced into the <see cref="Visibility.Collapsed"/>
/// </summary>
public bool Hide
{
get => _hide;
protected set
{
if (_hide == value)
return;
_hide = value;
OnPropertyChanged();
}
}
}
}

View File

@@ -1,4 +1,10 @@
using VRage.Game.ModAPI; using System.Windows.Controls;
using Sandbox.Game.World;
using Torch.API.Managers;
using Torch.Collections;
using Torch.Server.Managers;
using VRage.Game.Entity;
using VRage.Game.ModAPI;
using VRage.ModAPI; using VRage.ModAPI;
using VRageMath; using VRageMath;
@@ -7,14 +13,31 @@ namespace Torch.Server.ViewModels.Entities
public class EntityViewModel : ViewModel public class EntityViewModel : ViewModel
{ {
protected EntityTreeViewModel Tree { get; } protected EntityTreeViewModel Tree { get; }
public IMyEntity Entity { get; }
private IMyEntity _backing;
public IMyEntity Entity
{
get => _backing;
protected set
{
_backing = value;
OnPropertyChanged();
EntityControls = TorchBase.Instance?.Managers.GetManager<EntityControlManager>()?.BoundModels(this);
// ReSharper disable once ExplicitCallerInfoArgument
OnPropertyChanged(nameof(EntityControls));
}
}
public long Id => Entity.EntityId; public long Id => Entity.EntityId;
public MtObservableList<EntityControlViewModel> EntityControls { get; private set; }
public virtual string Name public virtual string Name
{ {
get => Entity.DisplayName; get => Entity?.DisplayName ?? (Entity != null ? $"eid:{Entity.EntityId}" : "nil");
set set
{ {
if (Entity!=null)
TorchBase.Instance.InvokeBlocking(() => Entity.DisplayName = value); TorchBase.Instance.InvokeBlocking(() => Entity.DisplayName = value);
OnPropertyChanged(); OnPropertyChanged();
} }
@@ -22,12 +45,13 @@ namespace Torch.Server.ViewModels.Entities
public virtual string Position public virtual string Position
{ {
get => Entity.GetPosition().ToString(); get => Entity?.GetPosition().ToString();
set set
{ {
if (!Vector3D.TryParse(value, out Vector3D v)) if (!Vector3D.TryParse(value, out Vector3D v))
return; return;
if (Entity != null)
TorchBase.Instance.InvokeBlocking(() => Entity.SetPosition(v)); TorchBase.Instance.InvokeBlocking(() => Entity.SetPosition(v));
OnPropertyChanged(); OnPropertyChanged();
} }

Some files were not shown because too many files have changed in this diff Show More