forked from ss13remake/ss13remake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clientside stuff in DebugConsole.cs Serverside stuff in ClientConsoleHost.cs Client processes console commands and sends them to server if you tell it to. Server processes same command , does stuff and answers client if you tell it to. Sorry about the messy split.
- Loading branch information
keelin
committed
Nov 14, 2013
1 parent
a253efe
commit d05d7fc
Showing
20 changed files
with
609 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using GameObject; | ||
|
||
namespace ClientInterfaces.GOC | ||
{ | ||
public interface IParticleSystemComponent : IComponent | ||
{ | ||
void AddParticleSystem(string name, bool active); | ||
void RemoveParticleSystem(string name); | ||
void SetParticleSystemActive(string name, bool active); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
254 changes: 254 additions & 0 deletions
254
ClientServices/UserInterface/Components/DebugConsole.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,254 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using ClientInterfaces.Configuration; | ||
using ClientInterfaces.GOC; | ||
using ClientInterfaces.Map; | ||
using ClientInterfaces.Network; | ||
using ClientInterfaces.Player; | ||
using ClientInterfaces.Resource; | ||
using ClientInterfaces.UserInterface; | ||
using GameObject; | ||
using GorgonLibrary; | ||
using GorgonLibrary.Graphics; | ||
using GorgonLibrary.InputDevices; | ||
using Lidgren.Network; | ||
using SS13.IoC; | ||
using SS13_Shared; | ||
using SS13_Shared.GO; | ||
using SS13_Shared.Utility; | ||
|
||
namespace ClientServices.UserInterface.Components | ||
{ | ||
public class DebugConsole : ScrollableContainer | ||
{ | ||
private Textbox input; | ||
private List<Label> lines = new List<Label>(); | ||
private int last_y = 0; | ||
|
||
public DebugConsole(string uniqueName, Size size, IResourceManager resourceManager) : base(uniqueName, size, resourceManager) | ||
{ | ||
input = new Textbox(size.Width, resourceManager); | ||
input.ClearFocusOnSubmit = false; | ||
input.drawColor = Color.FromArgb(100, Color.Gray); | ||
input.textColor = Color.FloralWhite; | ||
input.OnSubmit += new Textbox.TextSubmitHandler(input_OnSubmit); | ||
this.BackgroundColor = Color.FromArgb(100, Color.Gray); | ||
this.DrawBackground = true; | ||
this.DrawBorder = true; | ||
Update(0); | ||
} | ||
|
||
void input_OnSubmit(string text, Textbox sender) | ||
{ | ||
AddLine(text, Color.FloralWhite); | ||
ProcessCommand(text); | ||
} | ||
|
||
public void AddLine(string text, Color color) | ||
{ | ||
Label newLabel = new Label(text, "MICROGBE", this._resourceManager); | ||
newLabel.Position = new Point(5, last_y); | ||
newLabel.TextColor = color; | ||
newLabel.Update(0); | ||
last_y = newLabel.ClientArea.Bottom; | ||
components.Add(newLabel); | ||
} | ||
|
||
public override void Update(float frameTime) | ||
{ | ||
base.Update(frameTime); | ||
if (input != null) | ||
{ | ||
input.Position = new Point(ClientArea.Left, ClientArea.Bottom); | ||
input.Update(frameTime); | ||
} | ||
} | ||
|
||
public override void ToggleVisible() | ||
{ | ||
var netMgr = IoCManager.Resolve<INetworkManager>(); | ||
base.ToggleVisible(); | ||
if (IsVisible()) | ||
{ | ||
IoCManager.Resolve<IUserInterfaceManager>().SetFocus(input); | ||
netMgr.MessageArrived += new EventHandler<IncomingNetworkMessageArgs>(netMgr_MessageArrived); | ||
} | ||
else | ||
{ | ||
netMgr.MessageArrived -= new EventHandler<IncomingNetworkMessageArgs>(netMgr_MessageArrived); | ||
} | ||
} | ||
|
||
void netMgr_MessageArrived(object sender, IncomingNetworkMessageArgs e) | ||
{ | ||
//Make sure we reset the position - we might recieve this message after the gamestates. | ||
if (e.Message.Position > 0) e.Message.Position = 0; | ||
if (e.Message.MessageType == NetIncomingMessageType.Data && (NetMessage)e.Message.PeekByte() == NetMessage.ConsoleCommandReply) | ||
{ | ||
e.Message.ReadByte(); | ||
AddLine("Server: " + e.Message.ReadString(), Color.RoyalBlue); | ||
} | ||
//Again, make sure we reset the position - we might get it before the gamestate and then that would break. | ||
e.Message.Position = 0; | ||
} | ||
|
||
public override void Render() | ||
{ | ||
base.Render(); | ||
if (input != null) input.Render(); | ||
} | ||
|
||
public override void Dispose() | ||
{ | ||
base.Dispose(); | ||
input.Dispose(); | ||
} | ||
|
||
public override bool MouseDown(MouseInputEventArgs e) | ||
{ | ||
if (!base.MouseDown(e)) | ||
if (input.MouseDown(e)) | ||
{ | ||
IoCManager.Resolve<IUserInterfaceManager>().SetFocus(input); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public override bool MouseUp(MouseInputEventArgs e) | ||
{ | ||
if (!base.MouseUp(e)) | ||
return input.MouseUp(e); | ||
else return false; | ||
} | ||
|
||
public override void MouseMove(MouseInputEventArgs e) | ||
{ | ||
base.MouseMove(e); | ||
input.MouseMove(e); | ||
} | ||
|
||
public override bool MouseWheelMove(MouseInputEventArgs e) | ||
{ | ||
if (!base.MouseWheelMove(e)) | ||
return input.MouseWheelMove(e); | ||
else return false; | ||
} | ||
|
||
public override bool KeyDown(KeyboardInputEventArgs e) | ||
{ | ||
if (!base.KeyDown(e)) | ||
return input.KeyDown(e); | ||
else return false; | ||
} | ||
|
||
/// <summary> | ||
/// Processes commands (chat messages starting with /) | ||
/// </summary> | ||
/// <param name="text">input text</param> | ||
private void ProcessCommand(string text) | ||
{ | ||
//Commands are processed locally and then sent to the server to be processed there again. | ||
var args = new List<string>(); | ||
|
||
CommandParsing.ParseArguments(text, args); | ||
|
||
string command = args[0]; | ||
|
||
//Entity player; | ||
//var entMgr = IoCManager.Resolve<IEntityManager>(); | ||
//var plrMgr = IoCManager.Resolve<IPlayerManager>(); | ||
//player = plrMgr.ControlledEntity; | ||
//IoCManager.Resolve<INetworkManager>(). | ||
|
||
switch (command) | ||
{ | ||
case "addparticles": //This is only clientside. | ||
if (args.Count >= 3) | ||
{ | ||
Entity target = null; | ||
if (args[1].ToLowerInvariant() == "player") | ||
{ | ||
var plrMgr = IoCManager.Resolve<IPlayerManager>(); | ||
if (plrMgr != null) | ||
if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity; | ||
} | ||
else | ||
{ | ||
var entMgr = IoCManager.Resolve<IEntityManagerContainer>(); | ||
if (entMgr != null) | ||
{ | ||
int entUid = int.Parse(args[1]); | ||
target = entMgr.EntityManager.GetEntity(entUid); | ||
} | ||
} | ||
|
||
if (target != null) | ||
{ | ||
if (!target.HasComponent(ComponentFamily.Particles)) | ||
{ | ||
var entMgr = IoCManager.Resolve<IEntityManagerContainer>(); | ||
var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent"); | ||
target.AddComponent(ComponentFamily.Particles, compo); | ||
} | ||
else | ||
{ | ||
var entMgr = IoCManager.Resolve<IEntityManagerContainer>(); | ||
var compo = (IParticleSystemComponent)entMgr.EntityManager.ComponentFactory.GetComponent("ParticleSystemComponent"); | ||
target.AddComponent(ComponentFamily.Particles, compo); | ||
} | ||
} | ||
} | ||
SendServerConsoleCommand(text); //Forward to server. | ||
break; | ||
case "removeparticles": | ||
if (args.Count >= 3) | ||
{ | ||
Entity target = null; | ||
if (args[1].ToLowerInvariant() == "player") | ||
{ | ||
var plrMgr = IoCManager.Resolve<IPlayerManager>(); | ||
if (plrMgr != null) | ||
if (plrMgr.ControlledEntity != null) target = plrMgr.ControlledEntity; | ||
} | ||
else | ||
{ | ||
var entMgr = IoCManager.Resolve<IEntityManager>(); | ||
if (entMgr != null) | ||
{ | ||
int entUid = int.Parse(args[1]); | ||
target = entMgr.GetEntity(entUid); | ||
} | ||
} | ||
|
||
if (target != null) | ||
{ | ||
if (target.HasComponent(ComponentFamily.Particles)) | ||
{ | ||
IParticleSystemComponent compo = (IParticleSystemComponent)target.GetComponent(ComponentFamily.Particles); | ||
compo.RemoveParticleSystem(args[2]); | ||
} | ||
} | ||
} | ||
SendServerConsoleCommand(text); //Forward to server. | ||
break; | ||
default: | ||
SendServerConsoleCommand(text); //Forward to server. | ||
break; | ||
} | ||
} | ||
|
||
private void SendServerConsoleCommand(string text) | ||
{ | ||
var netMgr = IoCManager.Resolve<INetworkManager>(); | ||
if (netMgr != null && netMgr.IsConnected) | ||
{ | ||
NetOutgoingMessage outMsg = netMgr.CreateMessage(); | ||
outMsg.Write((byte) NetMessage.ConsoleCommand); | ||
outMsg.Write(text); | ||
netMgr.SendMessage(outMsg, NetDeliveryMethod.ReliableUnordered); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.