source: binary-improvements/7dtd-server-fixes/src/NetConnections/ConsoleOutputSeparator.cs@ 225

Last change on this file since 225 was 224, checked in by alloc, 10 years ago

A11 preps

File size: 2.6 KB
RevLine 
[107]1using System;
2using System.Collections.Generic;
3using System.Threading;
4using UnityEngine;
5
[132]6namespace 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;
[224]24 private static int issuerOfCurrentClientCommand = -1;
[132]25 private static IConnection issuerOfCurrentCommand;
[107]26
[224]27 public static void C_ExecuteCmdFromClient (ConsoleSdtd console, int _entityId, string _playerName, string _playerID, string _command)
[130]28 {
[213]29 Log.Out ("Executed command \"" + _command + "\" from player \"" + _playerName + "\"");
[107]30
[189]31 lock (netCommandQueue) {
[130]32 isCurrentCommandFromClient = true;
[224]33 issuerOfCurrentClientCommand = _entityId;
34
35 string[] array = _command.Split (' ');
36 if (array.Length == 0) {
37 C_SendResult (console, "*** ERROR: empty command '" + _command + "'");
38 } else {
39 ConsoleCommand cmd = console.getCommand (_command);
40 if (cmd != null) {
41 string[] array2 = new string[array.Length - 1];
42 for (int i = 1; i < array.Length; i++) {
43 array2 [i - 1] = array [i];
44 }
45 cmd.ExecuteRemote (_playerID, array2);
46 } else {
47 C_SendResult (console, "*** ERROR: unknown command '" + array [0] + "'");
48 }
49 }
50
[130]51 isCurrentCommandFromClient = false;
52 }
53
[107]54 }
55
[130]56 public static void C_SendResult (ConsoleSdtd console, string _line)
57 {
58 if (isCurrentCommandFromClient) {
[224]59 CommonMappingFunctions.GetConnectionManager ().SendPackage (new NetPackage_ConsoleCmdClient (_line, false), new PackageDestinationSingleEntityID (issuerOfCurrentClientCommand));
[130]60 } else {
[132]61 if (console.telnetServer != null && issuerOfCurrentCommand != null)
[190]62 issuerOfCurrentCommand.SendLine (_line);
[130]63 else if (ControlPanel.IsStarted ())
64 ControlPanel.AddTextToOutputBuffer (_line);
65 }
[107]66 }
67
[130]68 public static void C_Run (ConsoleSdtd console)
69 {
[132]70 if (netCommandQueue.Count > 0) {
[189]71 lock (netCommandQueue) {
[132]72 issuerOfCurrentCommand = netCommandQueue [0].client;
[189]73 try {
74 console.ExecuteRemoteCmdInternal (netCommandQueue [0].command, false);
75 } catch (Exception e) {
76 Log.Out("Exception while executing command: " + e);
77 }
[132]78 netCommandQueue.RemoveAt (0);
79 issuerOfCurrentCommand = null;
[130]80 }
81 }
82 }
83
[132]84 public static void QueueNetCommand (string _line, IConnection _con)
[130]85 {
[189]86 lock (netCommandQueue) {
[132]87 netCommandQueue.Add (new NetCommand (_line, _con));
[107]88 }
89 }
90 }
91}
Note: See TracBrowser for help on using the repository browser.