1
Fork 0
mirror of https://bitbucket.org/Ioncannon/project-meteor-server.git synced 2025-04-20 11:47:48 +00:00
project-meteor-server/FFXIVClassic Map Server/CommandProcessor.cs

153 lines
5.5 KiB
C#
Raw Normal View History

2016-04-06 15:22:26 -07:00
using System;
using System.Collections.Generic;
using System.Linq;
using FFXIVClassic.Common;
2016-04-06 15:22:26 -07:00
using FFXIVClassic_Map_Server.dataobjects;
2016-08-22 10:43:04 -04:00
2016-04-06 15:22:26 -07:00
using System.IO;
using FFXIVClassic_Map_Server.packets.send.actor;
using FFXIVClassic_Map_Server.packets.send;
using FFXIVClassic_Map_Server.lua;
2016-09-26 16:20:01 -04:00
using FFXIVClassic_Map_Server.Actors;
namespace FFXIVClassic_Map_Server
2016-04-06 15:34:04 -07:00
{
class CommandProcessor
{
2016-04-09 12:38:15 -07:00
private static Dictionary<uint, Item> gamedataItems = Server.GetGamedataItems();
// For the moment, this is the only predefined item
// TODO: make a list/enum in the future so that items can be given by name, instead of by id
const UInt32 ITEM_GIL = 1000001;
2016-06-15 00:08:05 +01:00
public void ChangeProperty(uint id, uint value, string target)
2016-04-06 15:34:04 -07:00
{
2016-06-15 00:08:05 +01:00
SetActorPropetyPacket ChangeProperty = new SetActorPropetyPacket(target);
2016-04-06 15:34:04 -07:00
2016-06-15 00:08:05 +01:00
ChangeProperty.SetTarget(target);
ChangeProperty.AddInt(id, value);
ChangeProperty.AddTarget();
2016-04-06 15:34:04 -07:00
Dictionary<uint, Session> sessionList = Server.GetServer().GetSessionList();
foreach (KeyValuePair<uint, Session> entry in sessionList)
2016-04-06 15:34:04 -07:00
{
SubPacket ChangePropertyPacket = ChangeProperty.BuildPacket((entry.Value.id), (entry.Value.id));
2016-04-06 15:34:04 -07:00
BasePacket packet = BasePacket.CreatePacket(ChangePropertyPacket, true, false);
packet.DebugPrintPacket();
2016-04-06 15:34:04 -07:00
entry.Value.QueuePacket(packet);
2016-04-06 15:34:04 -07:00
}
}
/// <summary>
/// We only use the default options for SendMessagePacket.
/// May as well make it less unwieldly to view
/// </summary>
/// <param name="client"></param>
/// <param name="message"></param>
private void SendMessage(Session session, String message)
{
if (session != null)
session.GetActor().QueuePacket(SendMessagePacket.BuildPacket(session.id, session.id, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", message));
}
internal bool DoCommand(string input, Session session)
2016-04-06 15:34:04 -07:00
{
if (!input.Any() || input.Equals(""))
2016-06-16 01:50:13 +01:00
return false;
2016-04-06 15:34:04 -07:00
input.Trim();
input = input.StartsWith("!") ? input.Substring(1) : input;
2016-04-08 00:48:34 -07:00
var split = input.Split('"')
.Select((str, index) => index % 2 == 0
? str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
: new String[] { str }
)
2016-06-16 01:50:13 +01:00
.SelectMany(str => str).ToArray();
2016-04-06 15:34:04 -07:00
split = split.Select(temp => temp.ToLower()).ToArray(); // Ignore case on commands
2016-04-08 00:48:34 -07:00
var cmd = split[0];
2016-06-16 01:50:13 +01:00
if (cmd.Any())
{
// if client isnt null, take player to be the player actor
2016-09-26 16:20:01 -04:00
Player player = null;
if (session != null)
player = session.GetActor();
2016-06-16 01:50:13 +01:00
if (cmd.Equals("help"))
{
// if there's another string after this, take it as the command we want the description for
if (split.Length > 1)
{
LuaEngine.RunGMCommand(player, split[1], null, true);
return true;
}
// print out all commands
foreach (var str in Directory.GetFiles("./scripts/commands/gm/"))
{
var c = str.Replace(".lua", "");
c = c.Replace("./scripts/commands/gm/", "");
LuaEngine.RunGMCommand(player, c, null, true);
}
return true;
}
LuaEngine.RunGMCommand(player, cmd.ToString(), split.ToArray());
return true;
}
// Debug
//SendMessage(client, string.Join(",", split));
if (split.Length >= 1)
{
// TODO: reloadzones
#region !reloaditems
if (split[0].Equals("reloaditems"))
2016-04-06 15:34:04 -07:00
{
Program.Log.Info(String.Format("Got request to reload item gamedata"));
SendMessage(session, "Reloading Item Gamedata...");
2016-04-06 15:34:04 -07:00
gamedataItems.Clear();
gamedataItems = Database.GetItemGamedata();
Program.Log.Info(String.Format("Loaded {0} items.", gamedataItems.Count));
SendMessage(session, String.Format("Loaded {0} items.", gamedataItems.Count));
2016-04-06 15:34:04 -07:00
return true;
2016-04-08 00:48:34 -07:00
}
#endregion
2016-04-08 00:48:34 -07:00
#region !property
2016-04-06 15:34:04 -07:00
else if (split[0].Equals("property"))
{
if (split.Length == 4)
{
ChangeProperty(Utils.MurmurHash2(split[1], 0), Convert.ToUInt32(split[2], 16), split[3]);
2016-04-06 15:34:04 -07:00
}
return true;
2016-04-08 00:48:34 -07:00
}
#endregion
2016-04-08 00:48:34 -07:00
#region !property2
2016-04-06 15:34:04 -07:00
else if (split[0].Equals("property2"))
{
if (split.Length == 4)
{
ChangeProperty(Convert.ToUInt32(split[1], 16), Convert.ToUInt32(split[2], 16), split[3]);
2016-04-06 15:34:04 -07:00
}
return true;
2016-04-08 00:48:34 -07:00
}
#endregion
2016-04-06 15:34:04 -07:00
}
return false;
}
}
}