?
This commit is contained in:
12
Models/ApiException.cs
Normal file
12
Models/ApiException.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public class ApiException : Exception
|
||||
{
|
||||
public int Code { get; }
|
||||
|
||||
public ApiException(int code, string message) : base(message)
|
||||
{
|
||||
Code = code;
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Models/Command.cs
Normal file
15
Models/Command.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public static class Command
|
||||
{
|
||||
public const int CTL_START = 1;
|
||||
public const int CTL_BIND = 2;
|
||||
public const int CTL_HEARTBEAT = 3;
|
||||
public const int CTL_TCP_CONNECT = 4;
|
||||
public const int CTL_TCP_ACCEPT = 5;
|
||||
public const int CTL_TCP_ACCEPT_ACK = 6;
|
||||
public const int CTL_TCP_CLOSE = 7;
|
||||
public const int DATA_SEND = 21;
|
||||
public const int DATA_BROADCAST = 22;
|
||||
}
|
||||
}
|
||||
43
Models/MechaInfo.cs
Normal file
43
Models/MechaInfo.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public class MechaInfo
|
||||
{
|
||||
[JsonPropertyName("IsJoin")]
|
||||
public bool IsJoin { get; set; }
|
||||
|
||||
[JsonPropertyName("IpAddress")]
|
||||
public uint IpAddress { get; set; }
|
||||
|
||||
[JsonPropertyName("MusicID")]
|
||||
public int MusicID { get; set; }
|
||||
|
||||
[JsonPropertyName("Entrys")]
|
||||
public List<bool> Entrys { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("UserIDs")]
|
||||
public List<long> UserIDs { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("UserNames")]
|
||||
public List<string> UserNames { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("IconIDs")]
|
||||
public List<int> IconIDs { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("FumenDifs")]
|
||||
public List<int> FumenDifs { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("Rateing")]
|
||||
public List<double> Rateing { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("ClassValue")]
|
||||
public List<int> ClassValue { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("MaxClassValue")]
|
||||
public List<int> MaxClassValue { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("UserType")]
|
||||
public List<int> UserType { get; set; } = new();
|
||||
}
|
||||
}
|
||||
59
Models/Msg.cs
Normal file
59
Models/Msg.cs
Normal file
@@ -0,0 +1,59 @@
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public class Msg
|
||||
{
|
||||
public int Version { get; set; } = 1;
|
||||
public int Cmd { get; set; }
|
||||
public int Proto { get; set; }
|
||||
public int Sid { get; set; }
|
||||
public uint Src { get; set; }
|
||||
public ushort SrcPort { get; set; }
|
||||
public uint Dst { get; set; }
|
||||
public ushort DstPort { get; set; }
|
||||
public string? Data { get; set; }
|
||||
|
||||
public static Msg FromString(string line)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
throw new ArgumentException("Line cannot be null or empty", nameof(line));
|
||||
}
|
||||
|
||||
var parts = line.Split(',');
|
||||
var msg = new Msg();
|
||||
|
||||
if (parts.Length > 0 && !string.IsNullOrWhiteSpace(parts[0])) msg.Version = int.Parse(parts[0]);
|
||||
if (parts.Length > 1 && !string.IsNullOrWhiteSpace(parts[1])) msg.Cmd = int.Parse(parts[1]);
|
||||
if (parts.Length > 2 && !string.IsNullOrWhiteSpace(parts[2])) msg.Proto = int.Parse(parts[2]);
|
||||
if (parts.Length > 3 && !string.IsNullOrWhiteSpace(parts[3])) msg.Sid = int.Parse(parts[3]);
|
||||
if (parts.Length > 4 && !string.IsNullOrWhiteSpace(parts[4])) msg.Src = uint.Parse(parts[4]);
|
||||
if (parts.Length > 5 && !string.IsNullOrWhiteSpace(parts[5])) msg.SrcPort = ushort.Parse(parts[5]);
|
||||
if (parts.Length > 6 && !string.IsNullOrWhiteSpace(parts[6])) msg.Dst = uint.Parse(parts[6]);
|
||||
if (parts.Length > 7 && !string.IsNullOrWhiteSpace(parts[7])) msg.DstPort = ushort.Parse(parts[7]);
|
||||
if (parts.Length > 16 && !string.IsNullOrWhiteSpace(parts[16])) msg.Data = parts[16];
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Version},{Cmd},{Proto},{Sid},{Src},{SrcPort},{Dst},{DstPort},,,,,,,,,,{Data}";
|
||||
}
|
||||
|
||||
public Msg CloneWithNewData(string? newData)
|
||||
{
|
||||
return new Msg
|
||||
{
|
||||
Version = Version,
|
||||
Cmd = Cmd,
|
||||
Proto = Proto,
|
||||
Sid = Sid,
|
||||
Src = Src,
|
||||
SrcPort = SrcPort,
|
||||
Dst = Dst,
|
||||
DstPort = DstPort,
|
||||
Data = newData
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Models/Proto.cs
Normal file
8
Models/Proto.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public static class Proto
|
||||
{
|
||||
public const int TCP = 6;
|
||||
public const int UDP = 17;
|
||||
}
|
||||
}
|
||||
31
Models/RecruitInfo.cs
Normal file
31
Models/RecruitInfo.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public class RecruitInfo
|
||||
{
|
||||
[JsonPropertyName("MechaInfo")]
|
||||
public MechaInfo MechaInfo { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("MusicID")]
|
||||
public int MusicID { get; set; }
|
||||
|
||||
[JsonPropertyName("GroupID")]
|
||||
public int GroupID { get; set; }
|
||||
|
||||
[JsonPropertyName("EventModeID")]
|
||||
public bool EventModeID { get; set; }
|
||||
|
||||
[JsonPropertyName("JoinNumber")]
|
||||
public int JoinNumber { get; set; }
|
||||
|
||||
[JsonPropertyName("PartyStance")]
|
||||
public int PartyStance { get; set; }
|
||||
|
||||
[JsonPropertyName("_startTimeTicks")]
|
||||
public long StartTimeTicks { get; set; }
|
||||
|
||||
[JsonPropertyName("_recvTimeTicks")]
|
||||
public long RecvTimeTicks { get; set; }
|
||||
}
|
||||
}
|
||||
19
Models/RecruitRecord.cs
Normal file
19
Models/RecruitRecord.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public class RecruitRecord
|
||||
{
|
||||
[JsonPropertyName("RecruitInfo")]
|
||||
public RecruitInfo RecruitInfo { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("Keychip")]
|
||||
public string Keychip { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("Server")]
|
||||
public RelayServerInfo Server { get; set; } = new();
|
||||
|
||||
[JsonPropertyName("Time")]
|
||||
public long Time { get; set; }
|
||||
}
|
||||
}
|
||||
19
Models/RelayServerInfo.cs
Normal file
19
Models/RelayServerInfo.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace CatLink.Models
|
||||
{
|
||||
public class RelayServerInfo
|
||||
{
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("addr")]
|
||||
public string Addr { get; set; } = string.Empty;
|
||||
|
||||
[JsonPropertyName("port")]
|
||||
public int Port { get; set; }
|
||||
|
||||
[JsonPropertyName("official")]
|
||||
public bool Official { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user