[107] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Threading;
|
---|
| 4 | using UnityEngine;
|
---|
| 5 |
|
---|
[132] | 6 | namespace AllocsFixes.NetConnections
|
---|
[107] | 7 | {
|
---|
[130] | 8 | public class ConsoleOutputSeparator
|
---|
[107] | 9 | {
|
---|
[132] | 10 | public struct NetCommand
|
---|
[130] | 11 | {
|
---|
| 12 | public string command;
|
---|
[132] | 13 | public IConnection client;
|
---|
[107] | 14 |
|
---|
[132] | 15 | public NetCommand (string _cmd, IConnection _client)
|
---|
[130] | 16 | {
|
---|
| 17 | command = _cmd;
|
---|
| 18 | client = _client;
|
---|
| 19 | }
|
---|
[107] | 20 | }
|
---|
| 21 |
|
---|
[132] | 22 | private static List<NetCommand> netCommandQueue = new List<NetCommand> ();
|
---|
[130] | 23 | private static bool isCurrentCommandFromClient = false;
|
---|
[132] | 24 | private static IConnection issuerOfCurrentCommand;
|
---|
[107] | 25 |
|
---|
[130] | 26 | public static void C_ExecuteCmdFromClient (ConsoleSdtd console, NetworkPlayer _networkPlayer, string _playerID, string _command)
|
---|
| 27 | {
|
---|
| 28 | Log.Out ("Executed command \"" + _command + "\" from player \"" + _playerID + "\"");
|
---|
[107] | 29 |
|
---|
[132] | 30 | object obj = netCommandQueue;
|
---|
[130] | 31 | Monitor.Enter (obj);
|
---|
| 32 | try {
|
---|
| 33 | isCurrentCommandFromClient = true;
|
---|
| 34 | console.issuerOfCurrentClientCommand = _networkPlayer;
|
---|
| 35 | console.ExecuteClientCmdInternal (_playerID, _command);
|
---|
| 36 | isCurrentCommandFromClient = false;
|
---|
| 37 | } finally {
|
---|
| 38 | Monitor.Exit (obj);
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[107] | 41 | }
|
---|
| 42 |
|
---|
[130] | 43 | public static void C_SendResult (ConsoleSdtd console, string _line)
|
---|
| 44 | {
|
---|
| 45 | if (isCurrentCommandFromClient) {
|
---|
| 46 | console.gameManager.GetRPCNetworkView ().RPC ("RPC_Console", console.issuerOfCurrentClientCommand, new object[]
|
---|
[107] | 47 | {
|
---|
| 48 | _line,
|
---|
| 49 | false
|
---|
| 50 | }
|
---|
[130] | 51 | );
|
---|
| 52 | } else {
|
---|
[132] | 53 | if (console.telnetServer != null && issuerOfCurrentCommand != null)
|
---|
| 54 | NetTelnetServer.WriteToClient_Single (_line, issuerOfCurrentCommand);
|
---|
[130] | 55 | else if (ControlPanel.IsStarted ())
|
---|
| 56 | ControlPanel.AddTextToOutputBuffer (_line);
|
---|
| 57 | }
|
---|
[107] | 58 | }
|
---|
| 59 |
|
---|
[130] | 60 | public static void C_Run (ConsoleSdtd console)
|
---|
| 61 | {
|
---|
[132] | 62 | if (netCommandQueue.Count > 0) {
|
---|
| 63 | object obj = netCommandQueue;
|
---|
[130] | 64 | Monitor.Enter (obj);
|
---|
| 65 | try {
|
---|
[132] | 66 | issuerOfCurrentCommand = netCommandQueue [0].client;
|
---|
| 67 | console.ExecuteRemoteCmdInternal (netCommandQueue [0].command, false);
|
---|
| 68 | netCommandQueue.RemoveAt (0);
|
---|
| 69 | issuerOfCurrentCommand = null;
|
---|
[130] | 70 | } finally {
|
---|
| 71 | Monitor.Exit (obj);
|
---|
| 72 | }
|
---|
| 73 | }
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[132] | 76 | public static void QueueNetCommand (string _line, IConnection _con)
|
---|
[130] | 77 | {
|
---|
[132] | 78 | object obj = netCommandQueue;
|
---|
[107] | 79 | Monitor.Enter (obj);
|
---|
| 80 | try {
|
---|
[132] | 81 | netCommandQueue.Add (new NetCommand (_line, _con));
|
---|
[107] | 82 | } finally {
|
---|
| 83 | Monitor.Exit (obj);
|
---|
| 84 | }
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 | }
|
---|