[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 |
|
---|
[189] | 30 | lock (netCommandQueue) {
|
---|
[130] | 31 | isCurrentCommandFromClient = true;
|
---|
| 32 | console.issuerOfCurrentClientCommand = _networkPlayer;
|
---|
| 33 | console.ExecuteClientCmdInternal (_playerID, _command);
|
---|
| 34 | isCurrentCommandFromClient = false;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
[107] | 37 | }
|
---|
| 38 |
|
---|
[130] | 39 | public static void C_SendResult (ConsoleSdtd console, string _line)
|
---|
| 40 | {
|
---|
| 41 | if (isCurrentCommandFromClient) {
|
---|
| 42 | console.gameManager.GetRPCNetworkView ().RPC ("RPC_Console", console.issuerOfCurrentClientCommand, new object[]
|
---|
[107] | 43 | {
|
---|
| 44 | _line,
|
---|
| 45 | false
|
---|
| 46 | }
|
---|
[130] | 47 | );
|
---|
| 48 | } else {
|
---|
[132] | 49 | if (console.telnetServer != null && issuerOfCurrentCommand != null)
|
---|
| 50 | NetTelnetServer.WriteToClient_Single (_line, issuerOfCurrentCommand);
|
---|
[130] | 51 | else if (ControlPanel.IsStarted ())
|
---|
| 52 | ControlPanel.AddTextToOutputBuffer (_line);
|
---|
| 53 | }
|
---|
[107] | 54 | }
|
---|
| 55 |
|
---|
[130] | 56 | public static void C_Run (ConsoleSdtd console)
|
---|
| 57 | {
|
---|
[132] | 58 | if (netCommandQueue.Count > 0) {
|
---|
[189] | 59 | lock (netCommandQueue) {
|
---|
[132] | 60 | issuerOfCurrentCommand = netCommandQueue [0].client;
|
---|
[189] | 61 | try {
|
---|
| 62 | console.ExecuteRemoteCmdInternal (netCommandQueue [0].command, false);
|
---|
| 63 | } catch (Exception e) {
|
---|
| 64 | Log.Out("Exception while executing command: " + e);
|
---|
| 65 | }
|
---|
[132] | 66 | netCommandQueue.RemoveAt (0);
|
---|
| 67 | issuerOfCurrentCommand = null;
|
---|
[130] | 68 | }
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 |
|
---|
[132] | 72 | public static void QueueNetCommand (string _line, IConnection _con)
|
---|
[130] | 73 | {
|
---|
[189] | 74 | lock (netCommandQueue) {
|
---|
[132] | 75 | netCommandQueue.Add (new NetCommand (_line, _con));
|
---|
[107] | 76 | }
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|