mirror of
https://github.com/rafi1212122/PemukulPaku
synced 2025-12-13 15:54:35 +01:00
target command & weather api
This commit is contained in:
2
.github/workflows/dotnet.yml
vendored
2
.github/workflows/dotnet.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
dotnet-version: 6.0.x
|
dotnet-version: 6.0.x
|
||||||
- name: Download Resources
|
- name: Download Resources
|
||||||
run: curl -o Resources.zip ***REMOVED***
|
run: curl -o Resources.zip https://rafi12.cyou/files/Resources.zip
|
||||||
- name: Unzip Resources
|
- name: Unzip Resources
|
||||||
run: unzip -n Resources.zip -d Common
|
run: unzip -n Resources.zip -d Common
|
||||||
- name: Restore dependencies
|
- name: Restore dependencies
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ namespace PemukulPaku.GameServer.Commands
|
|||||||
/// <para>All, Handler should override all virtual methods in Command.</para>
|
/// <para>All, Handler should override all virtual methods in Command.</para>
|
||||||
/// <para>Console, Handler should override Run method with string[] args.</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>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>
|
/// </summary>
|
||||||
public abstract class Command
|
public abstract class Command
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
{
|
{
|
||||||
args.RemoveAt(0);
|
args.RemoveAt(0);
|
||||||
|
|
||||||
if (Cmd.CmdType == CommandType.All)
|
if (Cmd.CmdType == CommandType.All || Cmd.CmdType == CommandType.Console)
|
||||||
{
|
{
|
||||||
Cmd.Run(args.ToArray());
|
Cmd.Run(args.ToArray());
|
||||||
}
|
}
|
||||||
|
|||||||
35
GameServer/Commands/TargetCommand.cs
Normal file
35
GameServer/Commands/TargetCommand.cs
Normal 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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using Common;
|
using Common;
|
||||||
using Common.Resources.Proto;
|
using Common.Resources.Proto;
|
||||||
using Common.Utils;
|
using Common.Utils;
|
||||||
|
using PemukulPaku.GameServer.Commands;
|
||||||
using PemukulPaku.GameServer.Game;
|
using PemukulPaku.GameServer.Game;
|
||||||
|
|
||||||
namespace PemukulPaku.GameServer
|
namespace PemukulPaku.GameServer
|
||||||
@@ -96,6 +97,8 @@ namespace PemukulPaku.GameServer
|
|||||||
Player.SaveAll();
|
Player.SaveAll();
|
||||||
c.Debug("Player data saved to database");
|
c.Debug("Player data saved to database");
|
||||||
c.Warn($"{Id} disconnected");
|
c.Warn($"{Id} disconnected");
|
||||||
|
|
||||||
|
if (ReadLine.GetInstance().session == this) { ReadLine.GetInstance().session = null; }
|
||||||
Server.GetInstance().Sessions.Remove(Id);
|
Server.GetInstance().Sessions.Remove(Id);
|
||||||
Server.GetInstance().LogClients();
|
Server.GetInstance().LogClients();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,6 +59,30 @@ namespace HttpServer.Controllers
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
app.Map("/game_weather/weather/get_weather", (HttpContext ctx) =>
|
||||||
|
{
|
||||||
|
Weather weatherData = new()
|
||||||
|
{
|
||||||
|
Retcode = 0,
|
||||||
|
Message = "OK",
|
||||||
|
Data = new()
|
||||||
|
{
|
||||||
|
Timezone = 8,
|
||||||
|
Hourly = new()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Random random = new();
|
||||||
|
for (int i = 0; i < 24; i++)
|
||||||
|
{
|
||||||
|
DateTime time = DateTime.Now.Add(TimeSpan.FromHours(1) * i);
|
||||||
|
weatherData.Data.Hourly.Add(new() { Condition = 1, Date = time.ToString("yyyy-MM-dd"), Hour = time.Hour, Temp = random.Next(20, 30) });
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.Response.Headers.Add("Content-Type", "application/json");
|
||||||
|
return ctx.Response.WriteAsync(JsonConvert.SerializeObject(weatherData));
|
||||||
|
});
|
||||||
|
|
||||||
app.Map("/bh3_os/mdk/shield/api/loadConfig", (HttpContext ctx) =>
|
app.Map("/bh3_os/mdk/shield/api/loadConfig", (HttpContext ctx) =>
|
||||||
{
|
{
|
||||||
return ctx.Response.WriteAsJsonAsync(new
|
return ctx.Response.WriteAsJsonAsync(new
|
||||||
|
|||||||
@@ -20,5 +20,42 @@ namespace HttpServer.Models
|
|||||||
[JsonProperty("minimum")]
|
[JsonProperty("minimum")]
|
||||||
public string Minimum { get; set; }
|
public string Minimum { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public partial class Weather
|
||||||
|
{
|
||||||
|
[JsonProperty("retcode")]
|
||||||
|
public int Retcode { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("message")]
|
||||||
|
public string Message { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("data")]
|
||||||
|
public WeatherData Data { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public partial class WeatherData
|
||||||
|
{
|
||||||
|
[JsonProperty("timezone")]
|
||||||
|
public int Timezone { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("hourly")]
|
||||||
|
public List<HourlyData> Hourly { get; set; }
|
||||||
|
|
||||||
|
public partial class HourlyData
|
||||||
|
{
|
||||||
|
[JsonProperty("condition")]
|
||||||
|
public long Condition { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("hour")]
|
||||||
|
public long Hour { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("date")]
|
||||||
|
public string Date { get; set; }
|
||||||
|
|
||||||
|
[JsonProperty("temp")]
|
||||||
|
public long Temp { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
|
||||||
Reference in New Issue
Block a user