254 lines
9.2 KiB
C#
254 lines
9.2 KiB
C#
using System;
|
|
using System.Buffers.Binary;
|
|
using System.Runtime.InteropServices;
|
|
using BrewMonster.Network;
|
|
using BrewMonster.Scripts.Managers;
|
|
using CSNetwork;
|
|
using CSNetwork.GPDataType;
|
|
|
|
namespace BrewMonster.Scripts.Chat
|
|
{
|
|
struct chat_policy_parameter
|
|
{
|
|
short cmd_id;
|
|
|
|
int parameter_mask;
|
|
//if(parameter_mask & CHAT_PARAMETER_ROLEID) 1 int insert here
|
|
//if(parameter_mask & CHAT_PARAMETER_LOCALVAL0) 1 int insert here
|
|
//if(parameter_m ask & CHAT_PARAMETER_LOCALVAL1) 1 int insert here
|
|
//if(parameter_mask & CHAT_PARAMETER_LOCALVAL2) 1 int insert here
|
|
};
|
|
|
|
public struct chat_item_base
|
|
{
|
|
public short cmd_id;
|
|
}
|
|
|
|
public struct chat_equip_item
|
|
{
|
|
public short cmd_id;
|
|
public char where;
|
|
public short index;
|
|
}
|
|
|
|
struct chat_generalcard_collection
|
|
{
|
|
public short cmd_id;
|
|
public int card_id;
|
|
};
|
|
|
|
public static class CHAT_S2C
|
|
{
|
|
public struct chat_equip_item
|
|
{
|
|
public short cmd_id;
|
|
public int type;
|
|
public int expire_date;
|
|
public int proc_type;
|
|
public ushort content_length;
|
|
public byte[] content;
|
|
|
|
public int LenghtHeader()
|
|
{
|
|
return Marshal.SizeOf<short>() + (Marshal.SizeOf<int>() * 3) + Marshal.SizeOf<ushort>();
|
|
}
|
|
}
|
|
|
|
public enum EChatS2CCommand : short
|
|
{
|
|
CHAT_EQUIP_ITEM,
|
|
CHAT_GENERALCARD_COLLECTION,
|
|
CHAT_POLICYCHAT_PARAMETER,
|
|
}
|
|
|
|
public static EC_IvtrItem CreateChatItem(Octets data)
|
|
{
|
|
EC_IvtrItem pIvtrItem = null;
|
|
if (data.Size > 0)
|
|
{
|
|
chat_item_base pInfo = GPDataTypeHelper.FromBytes<chat_item_base>(data.ByteArray);
|
|
if (pInfo.cmd_id == (short)EChatS2CCommand.CHAT_EQUIP_ITEM)
|
|
{
|
|
chat_equip_item pItemInfo = default;
|
|
var sz = pItemInfo.LenghtHeader();
|
|
|
|
if (data.Size >= sz && sz + pItemInfo.content_length == data.Size)
|
|
{
|
|
if (pItemInfo.cmd_id == (short)EChatS2CCommand.CHAT_EQUIP_ITEM)
|
|
{
|
|
pIvtrItem = EC_IvtrItem.CreateItem(pItemInfo.type, pItemInfo.expire_date, 1);
|
|
if (pIvtrItem != null)
|
|
{
|
|
pIvtrItem.SetProcType(pItemInfo.proc_type);
|
|
pIvtrItem.SetItemInfo(pItemInfo.content, pItemInfo.content_length);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else if (pInfo.cmd_id == (short)EChatS2CCommand.CHAT_GENERALCARD_COLLECTION)
|
|
{
|
|
chat_generalcard_collection pItemInfo =
|
|
GPDataTypeHelper.FromBytes<chat_generalcard_collection>(data.ByteArray);
|
|
if (data.Size > Marshal.SizeOf<chat_generalcard_collection>())
|
|
{
|
|
if (pItemInfo.cmd_id == (short)EChatS2CCommand.CHAT_GENERALCARD_COLLECTION)
|
|
{
|
|
pIvtrItem = EC_IvtrItem.CreateItem(pItemInfo.card_id, 0, 1);
|
|
if (pIvtrItem != null)
|
|
{
|
|
pIvtrItem.GetDetailDataFromLocal();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return pIvtrItem;
|
|
}
|
|
|
|
[System.Flags]
|
|
public enum ChatParameterMask
|
|
{
|
|
CHAT_PARAMETER_ROLEID = 0x00000001,
|
|
CHAT_PARAMETER_LOCALVAL0 = 0x00000002,
|
|
CHAT_PARAMETER_LOCALVAL1 = 0x00000004,
|
|
CHAT_PARAMETER_LOCALVAL2 = 0x00000008
|
|
}
|
|
|
|
public class PolicyChatParameter
|
|
{
|
|
public int role_id = -1;
|
|
public string name = string.Empty;
|
|
public ChatParameterMask parameter_mask = 0;
|
|
|
|
private int localval_0 = -1;
|
|
private int localval_1 = -1;
|
|
private int localval_2 = -1;
|
|
|
|
EC_Game g_pGame;
|
|
|
|
public bool HasRoleID()
|
|
{
|
|
return (parameter_mask & ChatParameterMask.CHAT_PARAMETER_ROLEID) != 0;
|
|
}
|
|
|
|
public bool HasLocalValue(int valueNum)
|
|
{
|
|
switch (valueNum)
|
|
{
|
|
case 0:
|
|
return (parameter_mask & ChatParameterMask.CHAT_PARAMETER_LOCALVAL0) != 0;
|
|
case 1:
|
|
return (parameter_mask & ChatParameterMask.CHAT_PARAMETER_LOCALVAL1) != 0;
|
|
case 2:
|
|
return (parameter_mask & ChatParameterMask.CHAT_PARAMETER_LOCALVAL2) != 0;
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public void GetNameFromServer()
|
|
{
|
|
if (role_id != -1 && HasRoleID())
|
|
{
|
|
int[] arr = new int[1] { role_id };
|
|
UnityGameSession.Instance.GameSession.CmdCache.SendGetPlayerBriefInfo(1, arr, 1);
|
|
}
|
|
}
|
|
|
|
public void SetLocalValue(int localValue, int id)
|
|
{
|
|
switch (id)
|
|
{
|
|
case 0:
|
|
localval_0 = localValue;
|
|
parameter_mask |= ChatParameterMask.CHAT_PARAMETER_LOCALVAL0;
|
|
break;
|
|
case 1:
|
|
localval_1 = localValue;
|
|
parameter_mask |= ChatParameterMask.CHAT_PARAMETER_LOCALVAL1;
|
|
break;
|
|
case 2:
|
|
localval_2 = localValue;
|
|
parameter_mask |= ChatParameterMask.CHAT_PARAMETER_LOCALVAL2;
|
|
break;
|
|
}
|
|
}
|
|
|
|
public bool TryGetLocalValue(int localVariableID, out int localVariable)
|
|
{
|
|
localVariable = -1;
|
|
|
|
if (!HasLocalValue(localVariableID))
|
|
return false;
|
|
|
|
switch (localVariableID)
|
|
{
|
|
case 0: localVariable = localval_0; break;
|
|
case 1: localVariable = localval_1; break;
|
|
case 2: localVariable = localval_2; break;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool IsNameReady()
|
|
{
|
|
return HasRoleID() ? !string.IsNullOrEmpty(name) : true;
|
|
}
|
|
}
|
|
|
|
public static PolicyChatParameter CreatPolicyChatParameter(Octets data)
|
|
{
|
|
PolicyChatParameter result = null;
|
|
if (data.Size >= Marshal.SizeOf(typeof(chat_item_base)))
|
|
{
|
|
chat_item_base pInfo = GPDataTypeHelper.FromBytes<chat_item_base>(data.ByteArray);
|
|
if (pInfo.cmd_id == (short)EChatS2CCommand.CHAT_POLICYCHAT_PARAMETER)
|
|
{
|
|
if (data.Size >= Marshal.SizeOf(typeof(chat_policy_parameter)))
|
|
{
|
|
Byte pData = GPDataTypeHelper.FromBytes<Byte>(data.ByteArray,
|
|
Marshal.SizeOf(typeof(chat_policy_parameter)));
|
|
result = new PolicyChatParameter();
|
|
// Todo: Check logic
|
|
result.parameter_mask =
|
|
GPDataTypeHelper.FromBytes<ChatParameterMask>(data.ByteArray, sizeof(short));
|
|
/*int paraMask = result.parameter_mask;
|
|
if (paraMask & ChatParameterMask.CHAT_PARAMETER_ROLEID){
|
|
if (pData + sizeof(int) > data.end()){
|
|
return null;
|
|
}
|
|
result->SetRoleId(*(int*)pData);
|
|
pData += sizeof(int);
|
|
}
|
|
if (paraMask & ChatParameterMask.CHAT_PARAMETER_LOCALVAL0){
|
|
if (pData + sizeof(int) > data.end()){
|
|
return null;
|
|
}
|
|
result->SetLocaValue(*(int*)pData, 0);
|
|
pData += sizeof(int);
|
|
}
|
|
if (paraMask & ChatParameterMask.CHAT_PARAMETER_LOCALVAL1){
|
|
if (pData + sizeof(int) > data.end()){
|
|
return null;
|
|
}
|
|
result.SetLocaValue((int)pData, 1);
|
|
pData += sizeof(int);
|
|
}
|
|
if (paraMask & ChatParameterMask.CHAT_PARAMETER_LOCALVAL2){
|
|
if (pData + sizeof(int) > data.end()){
|
|
return null;
|
|
}
|
|
// Check logic
|
|
result.SetLocalValue((int)pData, 2);
|
|
pData += sizeof(int);
|
|
}*/
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
}
|
|
} |