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