ai前存档

This commit is contained in:
2026-05-27 19:47:06 +08:00
parent a73b4c7dd9
commit ecff13130f
37 changed files with 8434 additions and 1248 deletions
@@ -1,11 +1,58 @@
using Assets.MyGame.Scripts.Net;
using Assets.MyGame.Scripts.Net.WebResponses;
using Assets.MyGame.Scripts.Net.WebResponses.ChineseChess;
using Newtonsoft.Json;
using System;
using System.Text;
using Unity.VisualScripting;
using UnityEngine;
public partial class WebSocketSendList
{
public static string MakeKillFishSign(
string roomId,
string userId,
string fishNumber,
string fishId,
long gold,
long timespan,
string bulletId,
long timestamp,
string signKey
)
{
string rawStr = $"{roomId}|{userId}|{fishNumber}|{fishId}|{gold}|{timespan}|{bulletId}|{timestamp}";
return Sign(rawStr, signKey);
}
public static string MakeFireCannonSign(string roomId, string userId, long gold, int count, long timestamp, string signKey)
{
string rawStr = $"{roomId}|{userId}|{gold}|{count}|{timestamp}";
Debug.Log($"生成签名的原始字符串:{rawStr}");
return Sign(rawStr, signKey);
}
public static string Sign(string rawStr, string signKey)
{
string input = rawStr + "|" + signKey;
using (var md5 = System.Security.Cryptography.MD5.Create())
{
byte[] bytes = Encoding.UTF8.GetBytes(input);
byte[] hash = md5.ComputeHash(bytes);
// 转成 hex 字符串(前 8 位)
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString().Substring(0, 8);
}
}
/// <summary>
/// 获取房间信息
/// </summary>
@@ -13,7 +60,7 @@ public partial class WebSocketSendList
{
WebSocketManager.Instance.Send(SocketType.room, "{\"type\":1,\"target\":\"GetRoomList\",\"invocationId\":\"1\",\"arguments\":[\"" + GameManager.Instance.user.id + "\"," + (int)GameManager.Instance.gameData.currGameType + "," + leave + ","+ district + "]}");
}
/// <summary>
/// 打中鱼
/// </summary>
@@ -21,11 +68,76 @@ public partial class WebSocketSendList
/// <param name="userId"></param>
/// <param name="fishNumber">配置id</param>
/// <param name="fishId">唯一id</param>
public static void KillFish(string roomId, string userId, string fishNumber, string fishId,int paoBei)
public static void KillFish(
string roomId,
string userId,
string fishNumber,
string fishId,
int paoBei,
string bulletId,
string signKey
)
{
var sendObj = new WebSocketSendList("KillFish", roomId, userId, fishNumber, fishId, paoBei, DateTimeOffset.UtcNow.ToUnixTimeSeconds());
long timespan = BeijingTimeManager.Instance.CurrentTimestampMs; // 毫秒
long timestamp = timespan / 1000; // 秒级
// count 固定为 1
string sign = MakeKillFishSign(roomId, userId, fishNumber, fishId, paoBei, timespan, bulletId, timestamp, signKey);
var sendObj = new WebSocketSendList(
"KillFish",
roomId,
userId,
fishNumber,
fishId,
paoBei,
timespan,
bulletId,
timestamp,
sign
);
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
}
/// <summary>
/// 发射子弹
/// </summary>
/// <param name="roomId"></param>
/// <param name="userId"></param>
/// <param name="gold">单价</param>
/// <param name="count">数量</param>
/// <summary>
/// 发射子弹(与 KillFish 同结构版本)
/// </summary>
public static void FireCannon(
string roomId,
string userId,
long gold,
int count,
object extra,
string signKey
)
{
long timespan = BeijingTimeManager.Instance.CurrentTimestampMs; // 毫秒
long timestamp = timespan / 1000; // 秒级
// FireCannon 的签名规则与 KillFish 一样:roomId|userId|gold|count|timestamp
string sign = MakeFireCannonSign(roomId, userId, gold, count, timestamp, signKey);
var sendObj = new WebSocketSendList(
"FireCannon",
roomId,
userId,
gold,
count,
timestamp,
sign,
extra
);
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
}
/// <summary>
/// 发射子弹
/// </summary>