(tools, client, server) chore:Remove GeneralService

This commit is contained in:
2025-08-29 13:35:52 +08:00
parent c3e1730152
commit 8fd5e24865
10 changed files with 33 additions and 2863 deletions

View File

@ -15,7 +15,6 @@ namespace Network
private readonly GrpcChannel _channel;
private readonly GameService.GameServiceClient _game;
private readonly GeneralService.GeneralServiceClient _general;
public GrpcClient()
{
@ -26,17 +25,11 @@ namespace Network
_channel = GrpcChannel.ForAddress(ServerAddress, channelOptions);
_general = new GeneralService.GeneralServiceClient(_channel);
_game = new GameService.GameServiceClient(_channel);
Application.quitting += () => _channel.ShutdownAsync().Wait();
}
public async Task<ServerInfo> GetServerInfo()
{
return await _general.GetServerInfoAsync(new Empty());
}
public async Task<LoginResponse> Login(string username, string password)
{
return await _game.LoginAsync(new LoginRequest { Username = username, Password = password });

File diff suppressed because it is too large Load Diff

View File

@ -8,198 +8,6 @@
using grpc = global::Grpc.Core;
namespace Protocol {
public static partial class GeneralService
{
static readonly string __ServiceName = "protocol.GeneralService";
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
static void __Helper_SerializeMessage(global::Google.Protobuf.IMessage message, grpc::SerializationContext context)
{
#if !GRPC_DISABLE_PROTOBUF_BUFFER_SERIALIZATION
if (message is global::Google.Protobuf.IBufferMessage)
{
context.SetPayloadLength(message.CalculateSize());
global::Google.Protobuf.MessageExtensions.WriteTo(message, context.GetBufferWriter());
context.Complete();
return;
}
#endif
context.Complete(global::Google.Protobuf.MessageExtensions.ToByteArray(message));
}
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
static class __Helper_MessageCache<T>
{
public static readonly bool IsBufferMessage = global::System.Reflection.IntrospectionExtensions.GetTypeInfo(typeof(global::Google.Protobuf.IBufferMessage)).IsAssignableFrom(typeof(T));
}
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
static T __Helper_DeserializeMessage<T>(grpc::DeserializationContext context, global::Google.Protobuf.MessageParser<T> parser) where T : global::Google.Protobuf.IMessage<T>
{
#if !GRPC_DISABLE_PROTOBUF_BUFFER_SERIALIZATION
if (__Helper_MessageCache<T>.IsBufferMessage)
{
return parser.ParseFrom(context.PayloadAsReadOnlySequence());
}
#endif
return parser.ParseFrom(context.PayloadAsNewBuffer());
}
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
static readonly grpc::Marshaller<global::Protocol.Empty> __Marshaller_protocol_Empty = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Protocol.Empty.Parser));
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
static readonly grpc::Marshaller<global::Protocol.ServerInfo> __Marshaller_protocol_ServerInfo = grpc::Marshallers.Create(__Helper_SerializeMessage, context => __Helper_DeserializeMessage(context, global::Protocol.ServerInfo.Parser));
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
static readonly grpc::Method<global::Protocol.Empty, global::Protocol.ServerInfo> __Method_GetServerInfo = new grpc::Method<global::Protocol.Empty, global::Protocol.ServerInfo>(
grpc::MethodType.Unary,
__ServiceName,
"GetServerInfo",
__Marshaller_protocol_Empty,
__Marshaller_protocol_ServerInfo);
/// <summary>Service descriptor</summary>
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
get { return global::Protocol.MessageReflection.Descriptor.Services[0]; }
}
/// <summary>Base class for server-side implementations of GeneralService</summary>
[grpc::BindServiceMethod(typeof(GeneralService), "BindService")]
public abstract partial class GeneralServiceBase
{
/// <summary>
/// Get server info from server.
///
/// This parameter actually doesn't accept any arguments,
/// but it is still required owing to Protobuf grammar.
/// </summary>
/// <param name="request">The request received from the client.</param>
/// <param name="context">The context of the server-side call handler being invoked.</param>
/// <returns>The response to send back to the client (wrapped by a task).</returns>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public virtual global::System.Threading.Tasks.Task<global::Protocol.ServerInfo> GetServerInfo(global::Protocol.Empty request, grpc::ServerCallContext context)
{
throw new grpc::RpcException(new grpc::Status(grpc::StatusCode.Unimplemented, ""));
}
}
/// <summary>Client for GeneralService</summary>
public partial class GeneralServiceClient : grpc::ClientBase<GeneralServiceClient>
{
/// <summary>Creates a new client for GeneralService</summary>
/// <param name="channel">The channel to use to make remote calls.</param>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public GeneralServiceClient(grpc::ChannelBase channel) : base(channel)
{
}
/// <summary>Creates a new client for GeneralService that uses a custom <c>CallInvoker</c>.</summary>
/// <param name="callInvoker">The callInvoker to use to make remote calls.</param>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public GeneralServiceClient(grpc::CallInvoker callInvoker) : base(callInvoker)
{
}
/// <summary>Protected parameterless constructor to allow creation of test doubles.</summary>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
protected GeneralServiceClient() : base()
{
}
/// <summary>Protected constructor to allow creation of configured clients.</summary>
/// <param name="configuration">The client configuration.</param>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
protected GeneralServiceClient(ClientBaseConfiguration configuration) : base(configuration)
{
}
/// <summary>
/// Get server info from server.
///
/// This parameter actually doesn't accept any arguments,
/// but it is still required owing to Protobuf grammar.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
/// <param name="cancellationToken">An optional token for canceling the call.</param>
/// <returns>The response received from the server.</returns>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public virtual global::Protocol.ServerInfo GetServerInfo(global::Protocol.Empty request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
{
return GetServerInfo(request, new grpc::CallOptions(headers, deadline, cancellationToken));
}
/// <summary>
/// Get server info from server.
///
/// This parameter actually doesn't accept any arguments,
/// but it is still required owing to Protobuf grammar.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="options">The options for the call.</param>
/// <returns>The response received from the server.</returns>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public virtual global::Protocol.ServerInfo GetServerInfo(global::Protocol.Empty request, grpc::CallOptions options)
{
return CallInvoker.BlockingUnaryCall(__Method_GetServerInfo, null, options, request);
}
/// <summary>
/// Get server info from server.
///
/// This parameter actually doesn't accept any arguments,
/// but it is still required owing to Protobuf grammar.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="headers">The initial metadata to send with the call. This parameter is optional.</param>
/// <param name="deadline">An optional deadline for the call. The call will be cancelled if deadline is hit.</param>
/// <param name="cancellationToken">An optional token for canceling the call.</param>
/// <returns>The call object.</returns>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public virtual grpc::AsyncUnaryCall<global::Protocol.ServerInfo> GetServerInfoAsync(global::Protocol.Empty request, grpc::Metadata headers = null, global::System.DateTime? deadline = null, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken))
{
return GetServerInfoAsync(request, new grpc::CallOptions(headers, deadline, cancellationToken));
}
/// <summary>
/// Get server info from server.
///
/// This parameter actually doesn't accept any arguments,
/// but it is still required owing to Protobuf grammar.
/// </summary>
/// <param name="request">The request to send to the server.</param>
/// <param name="options">The options for the call.</param>
/// <returns>The call object.</returns>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public virtual grpc::AsyncUnaryCall<global::Protocol.ServerInfo> GetServerInfoAsync(global::Protocol.Empty request, grpc::CallOptions options)
{
return CallInvoker.AsyncUnaryCall(__Method_GetServerInfo, null, options, request);
}
/// <summary>Creates a new instance of client from given <c>ClientBaseConfiguration</c>.</summary>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
protected override GeneralServiceClient NewInstance(ClientBaseConfiguration configuration)
{
return new GeneralServiceClient(configuration);
}
}
/// <summary>Creates service definition that can be registered with a server</summary>
/// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public static grpc::ServerServiceDefinition BindService(GeneralServiceBase serviceImpl)
{
return grpc::ServerServiceDefinition.CreateBuilder()
.AddMethod(__Method_GetServerInfo, serviceImpl.GetServerInfo).Build();
}
/// <summary>Register service method with a service binder with or without implementation. Useful when customizing the service binding logic.
/// Note: this method is part of an experimental API that can change or be removed without any prior notice.</summary>
/// <param name="serviceBinder">Service methods will be bound by calling <c>AddMethod</c> on this object.</param>
/// <param name="serviceImpl">An object implementing the server-side handling logic.</param>
[global::System.CodeDom.Compiler.GeneratedCode("grpc_csharp_plugin", null)]
public static void BindService(grpc::ServiceBinderBase serviceBinder, GeneralServiceBase serviceImpl)
{
serviceBinder.AddMethod(__Method_GetServerInfo, serviceImpl == null ? null : new grpc::UnaryServerMethod<global::Protocol.Empty, global::Protocol.ServerInfo>(serviceImpl.GetServerInfo));
}
}
public static partial class GameService
{
static readonly string __ServiceName = "protocol.GameService";
@ -265,7 +73,7 @@ namespace Protocol {
/// <summary>Service descriptor</summary>
public static global::Google.Protobuf.Reflection.ServiceDescriptor Descriptor
{
get { return global::Protocol.MessageReflection.Descriptor.Services[1]; }
get { return global::Protocol.MessageReflection.Descriptor.Services[0]; }
}
/// <summary>Base class for server-side implementations of GameService</summary>

View File

@ -7,12 +7,7 @@ namespace Test
{
private async void Start()
{
var serverInfo = await GrpcClient.Instance.GetServerInfo();
Debug.Log($"Received info from server: {serverInfo}");
var loginResult = await GrpcClient.Instance.Login("野兽先辈", "114514");
Debug.Log($"Received login result: {loginResult.Result}");
}
}

17
Server/Cargo.lock generated
View File

@ -286,7 +286,7 @@ dependencies = [
"cfg-if",
"libc",
"r-efi",
"wasi 0.14.2+wasi-0.2.4",
"wasi 0.14.3+wasi-0.2.4",
]
[[package]]
@ -1183,11 +1183,11 @@ checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
[[package]]
name = "wasi"
version = "0.14.2+wasi-0.2.4"
version = "0.14.3+wasi-0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3"
checksum = "6a51ae83037bdd272a9e28ce236db8c07016dd0d50c27038b3f407533c030c95"
dependencies = [
"wit-bindgen-rt",
"wit-bindgen",
]
[[package]]
@ -1455,10 +1455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
[[package]]
name = "wit-bindgen-rt"
version = "0.39.0"
name = "wit-bindgen"
version = "0.45.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1"
dependencies = [
"bitflags",
]
checksum = "052283831dbae3d879dc7f51f3d92703a316ca49f91540417d38591826127814"

View File

@ -5,9 +5,7 @@ use tonic::transport::Server;
use tonic_web::GrpcWebLayer;
use crate::protocol::game_service_server::GameServiceServer;
use crate::protocol::general_service_server::GeneralServiceServer;
use crate::services::game_service::GameServiceImpl;
use crate::services::general_service::GeneralServiceImpl;
pub(crate) struct GrpcServer;
@ -15,14 +13,12 @@ impl GrpcServer {
pub(crate) async fn init() {
let addr = SocketAddr::new([127, 0, 0, 1].into(), 12345);
let general_service = GeneralServiceServer::new(GeneralServiceImpl);
let game_service = GameServiceServer::new(GameServiceImpl);
task::spawn(async move {
Server::builder()
.accept_http1(true)
.layer(GrpcWebLayer::new())
.add_service(general_service)
.add_service(game_service)
.serve(addr)
.await

1
Server/src/services.rs Normal file
View File

@ -0,0 +1 @@
pub(crate) mod game_service;

View File

@ -1,19 +0,0 @@
use tonic::{Request, Response, Status};
use crate::protocol::general_service_server::GeneralService;
use crate::protocol::{Empty, ServerInfo};
pub(crate) struct GeneralServiceImpl;
#[tonic::async_trait]
impl GeneralService for GeneralServiceImpl {
async fn get_server_info(
&self,
_request: Request<Empty>,
) -> Result<Response<ServerInfo>, Status> {
Ok(Response::new(ServerInfo {
lang: "Rust".into(),
ver: "0.1.0".into(),
}))
}
}

View File

@ -1,2 +0,0 @@
pub(crate) mod game_service;
pub(crate) mod general_service;

View File

@ -4,14 +4,6 @@ package protocol;
// Define services
service GeneralService {
// Get server info from server.
//
// This parameter actually doesn't accept any arguments,
// but it is still required owing to Protobuf grammar.
rpc GetServerInfo(Empty) returns (ServerInfo);
}
service GameService {
rpc Login(LoginRequest) returns (LoginResponse);
rpc Signup(SignupRequest) returns (SignupResponse);
@ -24,16 +16,9 @@ enum RequestResult {
Fail = 1;
}
message Empty {}
message ServerInfo {
string Lang = 1;
string ver = 2;
}
message LoginRequest {
string Username = 1;
string Password = 2;
string username = 1;
string password = 2;
}
message LoginResponse {
@ -42,64 +27,11 @@ message LoginResponse {
}
message SignupRequest {
string Username = 1;
string Password = 2;
string username = 1;
string password = 2;
}
message SignupResponse {
RequestResult result = 1;
string message = 2;
}
// 定义 FilePack 消息
message FilePack {
string filePath = 1;
bytes content = 2;
}
// 定义 DataPackListPack 消息
message DataPackListPack {
repeated Pair packIDAndVersion = 1;
// 定义内部的 Pair 消息(用于替代 Tuple<string, string>
message Pair {
string key = 1;
string value = 2;
}
}
// 定义 TileMapTablePack 消息
message TileMapTablePack {
map<int32, string> tileMapKey = 1; // 使用 int32 替代 int
}
// 定义 MapDataPack 消息
message MapDataPack {
Vector2 position = 1;
Vector2 size = 2;
repeated int32 tileMapType = 3; // 使用 int32 替代 int
}
// 定义 MonsterAttributes 消息
message MonsterAttributes {
int32 health = 1;
int32 moveSpeed = 2;
int32 attack = 3;
int32 defense = 4;
int32 attackSpeed = 5;
int32 attackRange = 6;
int32 attackTargetCount = 7;
}
// 定义 MonsterPack 消息
message MonsterPack {
int32 monsterID = 1;
Vector2 position = 2;
MonsterAttributes attributes = 3;
}
// 定义 Vector2 消息
message Vector2 {
float x = 1;
float y = 2;
}