2019-06-18 22:55:32 -04:00
|
|
|
|
/*
|
|
|
|
|
===========================================================================
|
|
|
|
|
Copyright (C) 2015-2019 Project Meteor Dev Team
|
|
|
|
|
|
|
|
|
|
This file is part of Project Meteor Server.
|
|
|
|
|
|
|
|
|
|
Project Meteor Server is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
Project Meteor Server is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
along with Project Meteor Server. If not, see <https:www.gnu.org/licenses/>.
|
|
|
|
|
===========================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-04-06 15:22:26 -07:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2022-02-16 15:30:32 -05:00
|
|
|
|
using Meteor.Map.DataObjects;
|
2016-08-22 10:43:04 -04:00
|
|
|
|
|
2016-04-06 15:22:26 -07:00
|
|
|
|
using System.IO;
|
2019-06-19 01:10:15 -04:00
|
|
|
|
using Meteor.Map.packets.send;
|
|
|
|
|
using Meteor.Map.lua;
|
|
|
|
|
using Meteor.Map.Actors;
|
2016-04-07 12:25:28 -07:00
|
|
|
|
|
2019-06-19 01:10:15 -04:00
|
|
|
|
namespace Meteor.Map
|
2016-04-06 15:34:04 -07:00
|
|
|
|
{
|
|
|
|
|
class CommandProcessor
|
|
|
|
|
{
|
2017-06-24 14:12:52 -04:00
|
|
|
|
private static Dictionary<uint, ItemData> gamedataItems = Server.GetGamedataItems();
|
2016-04-07 12:25:28 -07:00
|
|
|
|
|
2016-04-06 16:28:24 -07:00
|
|
|
|
const UInt32 ITEM_GIL = 1000001;
|
2016-08-29 12:37:41 -04:00
|
|
|
|
|
2016-04-06 19:55:12 -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>
|
2016-08-29 12:37:41 -04:00
|
|
|
|
private void SendMessage(Session session, String message)
|
2016-04-06 19:55:12 -07:00
|
|
|
|
{
|
2016-08-29 12:37:41 -04:00
|
|
|
|
if (session != null)
|
2017-06-27 16:55:14 -04:00
|
|
|
|
session.GetActor().QueuePacket(SendMessagePacket.BuildPacket(session.id, SendMessagePacket.MESSAGE_TYPE_GENERAL_INFO, "", message));
|
2016-04-06 19:55:12 -07:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-29 12:37:41 -04:00
|
|
|
|
internal bool DoCommand(string input, Session session)
|
2016-04-06 15:34:04 -07:00
|
|
|
|
{
|
2017-08-02 23:06:11 +01:00
|
|
|
|
if (!input.Any() || input.Equals("") || input.Length == 1)
|
2016-06-16 01:50:13 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
2016-04-06 15:34:04 -07:00
|
|
|
|
input.Trim();
|
2016-06-18 05:59:42 +01:00
|
|
|
|
input = input.StartsWith("!") ? input.Substring(1) : input;
|
2016-04-08 00:48:34 -07:00
|
|
|
|
|
2016-06-18 05:59:42 +01: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
|
|
|
|
|
2017-01-24 09:02:45 -05:00
|
|
|
|
split = split.ToArray(); // Ignore case on commands
|
2016-04-08 00:48:34 -07:00
|
|
|
|
|
2017-08-21 00:40:41 +01:00
|
|
|
|
if (split.Length > 0)
|
2016-06-16 01:50:13 +01:00
|
|
|
|
{
|
2017-08-21 00:40:41 +01:00
|
|
|
|
var cmd = split[0];
|
|
|
|
|
|
2016-06-16 01:50:13 +01:00
|
|
|
|
// 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
|
2022-01-27 17:38:15 -05:00
|
|
|
|
foreach (var str in Directory.GetFiles(ConfigConstants.OPTIONS_SCRIPTPATH + "/commands/gm/"))
|
2016-06-16 01:50:13 +01:00
|
|
|
|
{
|
|
|
|
|
var c = str.Replace(".lua", "");
|
2022-01-27 17:38:15 -05:00
|
|
|
|
c = c.Replace(ConfigConstants.OPTIONS_SCRIPTPATH + "/scripts/commands/gm/", "");
|
2016-06-16 01:50:13 +01:00
|
|
|
|
|
|
|
|
|
LuaEngine.RunGMCommand(player, c, null, true);
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LuaEngine.RunGMCommand(player, cmd.ToString(), split.ToArray());
|
|
|
|
|
return true;
|
2016-06-18 05:59:42 +01:00
|
|
|
|
}
|
|
|
|
|
// Debug
|
|
|
|
|
//SendMessage(client, string.Join(",", split));
|
|
|
|
|
|
2016-06-17 05:05:31 +01:00
|
|
|
|
if (split.Length >= 1)
|
2016-06-18 05:59:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
2016-06-24 20:52:30 +01:00
|
|
|
|
// TODO: reloadzones
|
|
|
|
|
|
2016-06-17 05:05:31 +01:00
|
|
|
|
#region !reloaditems
|
2016-06-18 05:59:42 +01:00
|
|
|
|
if (split[0].Equals("reloaditems"))
|
2016-04-06 15:34:04 -07:00
|
|
|
|
{
|
2016-06-14 22:54:02 +01:00
|
|
|
|
Program.Log.Info(String.Format("Got request to reload item gamedata"));
|
2016-08-29 12:37:41 -04:00
|
|
|
|
SendMessage(session, "Reloading Item Gamedata...");
|
2016-04-06 15:34:04 -07:00
|
|
|
|
gamedataItems.Clear();
|
2016-06-14 22:54:02 +01:00
|
|
|
|
gamedataItems = Database.GetItemGamedata();
|
|
|
|
|
Program.Log.Info(String.Format("Loaded {0} items.", gamedataItems.Count));
|
2016-08-29 12:37:41 -04:00
|
|
|
|
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
|
|
|
|
}
|
2016-04-07 12:25:28 -07:00
|
|
|
|
#endregion
|
2016-04-08 00:48:34 -07:00
|
|
|
|
|
2016-04-07 12:25:28 -07:00
|
|
|
|
#region !property
|
2016-04-06 15:34:04 -07:00
|
|
|
|
else if (split[0].Equals("property"))
|
|
|
|
|
{
|
|
|
|
|
if (split.Length == 4)
|
|
|
|
|
{
|
2017-01-24 09:02:45 -05:00
|
|
|
|
// 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
|
|
|
|
}
|
2016-04-07 12:25:28 -07:00
|
|
|
|
#endregion
|
2016-04-08 00:48:34 -07:00
|
|
|
|
|
2016-04-07 12:25:28 -07:00
|
|
|
|
#region !property2
|
2016-04-06 15:34:04 -07:00
|
|
|
|
else if (split[0].Equals("property2"))
|
|
|
|
|
{
|
|
|
|
|
if (split.Length == 4)
|
|
|
|
|
{
|
2017-01-24 09:02:45 -05:00
|
|
|
|
//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
|
|
|
|
}
|
2016-04-07 12:25:28 -07:00
|
|
|
|
#endregion
|
2016-04-06 15:34:04 -07:00
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|