gpt4 book ai didi

c# - 索引超出范围。必须为非负数且小于集合的大小。参数名称 : index

转载 作者:太空宇宙 更新时间:2023-11-03 21:45:04 26 4
gpt4 key购买 nike

我使用网络平台来验证我的用户是否允许使用应用程序,但如果可能的话,我有一些错误请求帮助我,谢谢你的帮助,我的错误是:

2013-07-04 15:06:14 - NPMessage: DEBUG: Dispatching a RPCAuthenticateValidateTicketMessage 2013-07-04 15:06:14 - NPMessage: ERROR: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: startIndex at System.BitConverter.ToUInt64(Byte[] value, Int32 startIndex) at NPx.RPCAuthenticateValidateTicketMessage.ReadTicket(Byte[] bytes) at NPx.RPCAuthenticateValidateTicketMessage.Process(NPHandler client) at NPx.NPMessage.Process()

我的来源是:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;

using NPx;

namespace NPx
{
public partial class RPCAuthenticateValidateTicketMessage : NPRPCMessage<AuthenticateValidateTicketMessage>
{
public override void Process(NPHandler client)
{
var ipNum = (uint)IPAddress.NetworkToHostOrder(Message.clientIP);
var ip = new IPAddress(BitConverter.GetBytes(ipNum));
var ticket = ReadTicket(Message.ticket);
var npid = Message.npid;

if (npid == 0)
{
npid = ticket.clientID;
}

var valid = false;
var groupID = 0;

if (ticket.version == 1)
{
if (client.NPID == (long)ticket.serverID)
{
if (npid == ticket.clientID)
{
var remoteClient = NPSocket.GetClient((long)ticket.clientID);
remoteClient.CurrentServer = client.NPID;

if (remoteClient != null && !remoteClient.Unclean)
{
Log.Debug("Ticket auth: remote address " + remoteClient.Address.Address.ToString());
Log.Debug("Ticket auth: message address " + ip.ToString());

if (ipNum == 0 || remoteClient.Address.Address.Equals(ip))
{
valid = true;

groupID = remoteClient.GroupID;

Log.Debug("Successfully authenticated a ticket for client " + remoteClient.NPID.ToString("x16"));
}
else
{
Log.Debug("Ticket auth: IP address didn't match.");
}
}
else
{
Log.Debug("Ticket auth: no such client");
}
}
else
{
Log.Debug("Ticket auth: NPID didn't match.");
}
}
else
{
Log.Debug("Ticket auth: server NPID didn't match.");
}
}
else
{
Log.Debug("Ticket auth: version didn't match.");
}

var reply = MakeResponse<AuthenticateValidateTicketResultMessage>(client);
reply.Message.result = (valid) ? 0 : 1;
reply.Message.groupID = groupID;
reply.Message.npid = npid;
reply.Send();
}

private class NPTicket
{
public int version;
public ulong clientID;
public ulong serverID;
public uint time;
}

private NPTicket ReadTicket(byte[] bytes)
{
var ticket = new NPTicket();
ticket.version = BitConverter.ToInt32(bytes, 0);

if (ticket.version == 1)
{
ticket.clientID = BitConverter.ToUInt64(bytes, 4);
ticket.serverID = BitConverter.ToUInt64(bytes, 12);
ticket.time = BitConverter.ToUInt32(bytes, 20);
}

return ticket;
}
}
....
}

最佳答案

在访问其位置 0、4、12 和 20 之前,检查 private NPTicket ReadTicket(byte[] bytes)bytes 的大小。

关于c# - 索引超出范围。必须为非负数且小于集合的大小。参数名称 : index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17468365/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com