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