target command & weather api

This commit is contained in:
rafi1212122
2023-05-31 16:33:25 +07:00
parent 3778da626c
commit ca4413c9ce
7 changed files with 102 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ namespace PemukulPaku.GameServer.Commands
/// <para>All, Handler should override all virtual methods in Command.</para>
/// <para>Console, Handler should override Run method with string[] args.</para>
/// <para>Player, Handler should override Run method with Player / Session args.</para>
/// <para>When making non console command please call the Run overload with Player from Session overload.</para>
/// </summary>
public abstract class Command
{

View File

@@ -25,7 +25,7 @@
{
args.RemoveAt(0);
if (Cmd.CmdType == CommandType.All)
if (Cmd.CmdType == CommandType.All || Cmd.CmdType == CommandType.Console)
{
Cmd.Run(args.ToArray());
}

View File

@@ -0,0 +1,35 @@
namespace PemukulPaku.GameServer.Commands
{
[CommandHandler("target", "Select session target for console command action", CommandType.Console)]
internal class TargetCommand : Command
{
public override void Run(string[] args)
{
if(args.Length == 0)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write("Selected Session: ");
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(ReadLine.GetInstance().session?.Id ?? "None");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Active Sessions:");
Console.ResetColor();
foreach (KeyValuePair<string, Session> session in Server.GetInstance().Sessions)
{
c.Trail(session.Key);
}
} else
{
if(Server.GetInstance().Sessions.TryGetValue(args[0], out Session? session))
{
ReadLine.GetInstance().session = session;
c.Log("Session set to " + session.Id);
}
else
{
c.Error("Session not found with key " + args[0]);
}
}
}
}
}

View File

@@ -2,6 +2,7 @@
using Common;
using Common.Resources.Proto;
using Common.Utils;
using PemukulPaku.GameServer.Commands;
using PemukulPaku.GameServer.Game;
namespace PemukulPaku.GameServer
@@ -96,6 +97,8 @@ namespace PemukulPaku.GameServer
Player.SaveAll();
c.Debug("Player data saved to database");
c.Warn($"{Id} disconnected");
if (ReadLine.GetInstance().session == this) { ReadLine.GetInstance().session = null; }
Server.GetInstance().Sessions.Remove(Id);
Server.GetInstance().LogClients();
}