Merge pull request #480 from gsy1519/dev

feat:  add binary message to SendMessage
This commit is contained in:
Timothy Liu 2023-04-29 15:31:30 +08:00 committed by GitHub
commit 898e0ce840
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 55 additions and 18 deletions

View File

@ -224,30 +224,67 @@ namespace Server
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
if (request.Message.Length > 256)
switch (request.MessageCase)
{
case SendMsg.MessageOneofCase.TextMessage:
{
if (request.TextMessage.Length > 256)
{
#if DEBUG
Console.WriteLine("Message string is too long!");
Console.WriteLine("Text message string is too long!");
#endif
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
else
{
MessageOfNews news = new();
news.News = request.Message;
news.FromId = request.PlayerId;
news.ToId = request.ToPlayerId;
lock (newsLock)
{
currentNews.Add(news);
}
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
MessageOfNews news = new();
news.TextMessage = request.TextMessage;
news.FromId = request.PlayerId;
news.ToId = request.ToPlayerId;
lock (newsLock)
{
currentNews.Add(news);
}
#if DEBUG
Console.WriteLine(news.News);
Console.WriteLine(news.TextMessage);
#endif
boolRes.ActSuccess = true;
return Task.FromResult(boolRes);
}
case SendMsg.MessageOneofCase.BinaryMessage:
{
if (request.BinaryMessage.Length > 256)
{
#if DEBUG
Console.WriteLine("Binary message string is too long!");
#endif
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
MessageOfNews news = new();
news.BinaryMessage = request.BinaryMessage;
news.FromId = request.PlayerId;
news.ToId = request.ToPlayerId;
lock (newsLock)
{
currentNews.Add(news);
}
#if DEBUG
Console.Write("BinaryMessageLength: ");
Console.WriteLine(news.BinaryMessage.Length);
#endif
boolRes.ActSuccess = true;
return Task.FromResult(boolRes);
}
default:
{
boolRes.ActSuccess = false;
return Task.FromResult(boolRes);
}
}
boolRes.ActSuccess = true;
return Task.FromResult(boolRes);
}
public override Task<BoolRes> PickProp(PropMsg request, ServerCallContext context)
{