mirror of
https://github.com/MikuLeaks/MikuSB.git
synced 2026-06-04 21:13:59 +00:00
enter intro cutscene
This commit is contained in:
6
GameServer/Server/Packet/Handler.cs
Normal file
6
GameServer/Server/Packet/Handler.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace MikuSB.GameServer.Server.Packet;
|
||||
|
||||
public abstract class Handler
|
||||
{
|
||||
public abstract Task OnHandle(Connection connection, byte[] data, ushort SeqNo = 0);
|
||||
}
|
||||
31
GameServer/Server/Packet/HandlerManager.cs
Normal file
31
GameServer/Server/Packet/HandlerManager.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace MikuSB.GameServer.Server.Packet;
|
||||
|
||||
public static class HandlerManager
|
||||
{
|
||||
public static Dictionary<int, Handler> handlers = [];
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
var classes = Assembly.GetExecutingAssembly().GetTypes(); // Get all classes in the assembly
|
||||
foreach (var cls in classes)
|
||||
{
|
||||
var attribute = (Opcode?)Attribute.GetCustomAttribute(cls, typeof(Opcode));
|
||||
|
||||
if (attribute != null) handlers.Add(attribute.CmdId, (Handler)Activator.CreateInstance(cls)!);
|
||||
}
|
||||
}
|
||||
|
||||
public static Handler? GetHandler(int cmdId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return handlers[cmdId];
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
7
GameServer/Server/Packet/Opcode.cs
Normal file
7
GameServer/Server/Packet/Opcode.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace MikuSB.GameServer.Server.Packet;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class Opcode(int cmdId) : Attribute
|
||||
{
|
||||
public int CmdId = cmdId;
|
||||
}
|
||||
50
GameServer/Server/Packet/Recv/Login/HandlerReqLogin.cs
Normal file
50
GameServer/Server/Packet/Recv/Login/HandlerReqLogin.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using MikuSB.Data;
|
||||
using MikuSB.Database;
|
||||
using MikuSB.Database.Account;
|
||||
using MikuSB.Database.Player;
|
||||
using MikuSB.GameServer.Game.Player;
|
||||
using MikuSB.GameServer.Server.Packet.Send.Login;
|
||||
using MikuSB.Proto;
|
||||
using MikuSB.TcpSharp;
|
||||
using MikuSB.Util;
|
||||
|
||||
namespace MikuSB.GameServer.Server.Packet.Recv.Login;
|
||||
|
||||
[Opcode(CmdIds.ReqLogin)]
|
||||
public class HandlerReqLogin : Handler
|
||||
{
|
||||
public override async Task OnHandle(Connection connection, byte[] data, ushort seqNo)
|
||||
{
|
||||
var req = ReqLogin.Parser.ParseFrom(data);
|
||||
var account = AccountData.GetAccountByUid(1);
|
||||
if (account == null)
|
||||
{
|
||||
AccountData.CreateAccount("MIKU", 0, "");
|
||||
account = AccountData.GetAccountByUid(1);
|
||||
if (account == null)
|
||||
{
|
||||
await connection.SendPacket(CmdIds.NtfLogout);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (!ResourceManager.IsLoaded)
|
||||
// resource manager not loaded, return
|
||||
return;
|
||||
var prev = Listener.GetActiveConnection(account.Uid);
|
||||
if (prev != null)
|
||||
{
|
||||
await connection.SendPacket(CmdIds.NtfLogout);
|
||||
prev.Stop();
|
||||
}
|
||||
|
||||
connection.State = SessionStateEnum.WAITING_FOR_LOGIN;
|
||||
var pd = DatabaseHelper.GetInstance<PlayerGameData>(account.Uid);
|
||||
connection.Player = pd == null ? new PlayerInstance(account.Uid) : new PlayerInstance(pd);
|
||||
|
||||
connection.DebugFile = Path.Combine(ConfigManager.Config.Path.LogPath, "Debug/", $"{account.Uid}/",
|
||||
$"Debug-{DateTime.Now:yyyy-MM-dd HH-mm-ss}.log");
|
||||
await connection.Player.OnEnterGame();
|
||||
connection.Player.Connection = connection;
|
||||
await connection.SendPacket(new PacketRspLogin(connection.Player!));
|
||||
}
|
||||
}
|
||||
29
GameServer/Server/Packet/Send/Login/PacketRspLogin.cs
Normal file
29
GameServer/Server/Packet/Send/Login/PacketRspLogin.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using MikuSB.GameServer.Game.Player;
|
||||
using MikuSB.TcpSharp;
|
||||
using MikuSB.Proto;
|
||||
using MikuSB.Util.Extensions;
|
||||
|
||||
namespace MikuSB.GameServer.Server.Packet.Send.Login;
|
||||
|
||||
public class PacketRspLogin : BasePacket
|
||||
{
|
||||
public PacketRspLogin(PlayerInstance player) : base(CmdIds.RspLogin)
|
||||
{
|
||||
var proto = new RspLogin
|
||||
{
|
||||
Timestamp = (uint)Extensions.GetUnixSec(),
|
||||
WorldChannel = 1,
|
||||
AreaId = 1,
|
||||
Data = new Player
|
||||
{
|
||||
Pid = (ulong)player.Data.Uid,
|
||||
Account = player.Data.Name,
|
||||
Name = player.Data.Name,
|
||||
Level = 80
|
||||
},
|
||||
NeedRename = false
|
||||
};
|
||||
|
||||
SetData(proto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user