C# - 无法从 UDP 获取服务器响应 - Black Ops Rcon
我正在为《使命召唤:黑色行动》创建一个 RCON Web 应用程序。 COD 使用 rcon 和 udp 数据包来发送和接收信息。使用以下代码,我已经能够使用 COD4 服务器发送和接收信息。现在 COD7 已经发布了,我不再收到回复。
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
client.Connect(IPAddress.Parse(gameServerIP), gameServerPort);
string command;
command = password + " " + rconCommand;
byte[] bufferTemp = Encoding.ASCII.GetBytes(command);
byte[] bufferSend = new byte[bufferTemp.Length + 5];
//intial 5 characters as per standard
bufferSend[0] = byte.Parse("255");
bufferSend[1] = byte.Parse("255");
bufferSend[2] = byte.Parse("255");
bufferSend[3] = byte.Parse("255");
bufferSend[4] = byte.Parse("02");
int j = 5;
for (int i = 0; i < bufferTemp.Length; i++)
{
bufferSend[j++] = bufferTemp[i];
}
//send rcon command and get response
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
client.Send(bufferSend, SocketFlags.None);
//big enough to receive response
byte[] bufferRec = new byte[65000];
client.Receive(bufferRec);
有人有什么想法吗? Black Ops 附带了自己的 Rcon 工具,我尝试使用 Wireshark 捕获要复制的传出数据包。我的应用程序和他们的应用程序之间的传出数据包几乎相同,只是当我使用我的应用程序时没有收到回复。
I'm creating an RCON web application for Call of Duty Black Ops. COD uses rcon and udp packets to send and receive information. Using the following code, I've been able to send and receive information with a COD4 server. Now that COD7 is out, I'm no longer receiving responses back.
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
client.Connect(IPAddress.Parse(gameServerIP), gameServerPort);
string command;
command = password + " " + rconCommand;
byte[] bufferTemp = Encoding.ASCII.GetBytes(command);
byte[] bufferSend = new byte[bufferTemp.Length + 5];
//intial 5 characters as per standard
bufferSend[0] = byte.Parse("255");
bufferSend[1] = byte.Parse("255");
bufferSend[2] = byte.Parse("255");
bufferSend[3] = byte.Parse("255");
bufferSend[4] = byte.Parse("02");
int j = 5;
for (int i = 0; i < bufferTemp.Length; i++)
{
bufferSend[j++] = bufferTemp[i];
}
//send rcon command and get response
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
client.Send(bufferSend, SocketFlags.None);
//big enough to receive response
byte[] bufferRec = new byte[65000];
client.Receive(bufferRec);
Does anyone have any ideas? Black Ops ships with its own Rcon tool that I've tried using Wireshark to capture the outgoing packets to copy. The outgoing packets between my application and theirs are next to identical, except I get no replies back when I use mine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我知道为什么,因为我自己制作了一个工具。
您的代码中的错误是: bufferSend[4] = byte.Parse("02");
好的是: bufferSend[4] = byte.Parse("00");
尝试一下,对我有用!
i knwo why cause i make a tool myself.
What's wrong in your code is that : bufferSend[4] = byte.Parse("02");
the good one is : bufferSend[4] = byte.Parse("00");
Try it, works for me!
这里是我的一段代码,我使用一个线程来运行它:
怎么做:
在你的类中设置私有命令,然后调用工作线程,当线程完成时,只需读取私有响应。
Here my piece of code, i use a thread to run it:
how to do:
in your class set the private command, then call the worker, when thread finish, just read the private response.
我正在使用 vb.net 做类似的事情
我已经为 COD MW 和 COD WW 编写了 rcon 工具,没有问题,但是到目前为止,我还无法从我的黑色行动服务器获得响应。
I am doing a similar thing using vb.net
I have written rcon tools for COD MW and COD WW no problem however so far I have not been able to get a response back from my black ops server.
事实上,我做了和你一样的事情,我使用 WireShark 来查看发送和接收的字节,并使用 steam 中为 Black Ops 提供的默认 rconTool 来查看发送和接收的字节。
其他提示:
命令“status”为您提供有关当前玩家的许多信息,但不提供每个玩家的团队信息。
您最好使用“teamstatus”,它为您提供相同的信息,但包含每个玩家的团队。
我现在很难完美地解析响应,但要给出一个可读的答案,请使用以下命令:
replace :
by:
这样,您将拥有一个数组,其中每个玩家单独排成一行。
顺便说一句:我是麦克,我现在已经注册了,不是今晚
编辑:oups,我没有注意到你已经尝试过 teamstatus 命令。
你需要查看client.Avalaible返回的数字,因为服务器一次只发送1168字节,所以如果client.Avalaible>1168,你需要第二个缓冲区来通过client.receive获取第二个流。
事实上,client.avalaible 只有两个可能的数字:1168 和 2336(是的,双倍)我不知道为什么,但他们没有设法发送确切数量的数据,缓冲区总是满或空。
我还注意到第二个 receive() 就像第一个缓冲区上的“粘贴”。
您将首先获得第一个 Receive() 的补充信息,然后是旧的“噪音”。
只要看一下,你就会明白我的意思。
我现在正在工作,但今晚我将发布我的代码来提供帮助。
In fact, i have done the saame thing as you, i used WireShark to look the byte sent and received with the default rconTool provide in steam for Black Ops.
Other tip:
The command "status" give you many information about the current players but not the team of each.
You better use "teamstatus" instead, this one give you the same information but with the team of each player.
I have trouble right now to perfectly parse the response, but to give a readeable answer use this:
replace :
by:
This way you'll have an array with each player separate in a row.
Btw: i'm mack, i'm now registered, wasn't this night
Edit: oups, i didn't notice you've already tried the teamstatus command.
You need to look at the number return by client.Avalaible, because the server only send 1168 byte at once, so if client.Avalaible>1168, you need a second buffer to get the second flow with client.receive.
In fact there's only two possible number for client.avalaible : 1168 and 2336 (yes, the double) i don't know why, but they didn't managed to send the exact number of data, the buffer is always full or empty.
I noticed also that the second receive() is like "paste" on the first buffer.
YOu'll have at hte begginig the complementary information of the first Receive(), then the "noise" of the old one.
Just take a look, you will see what i mean.
I'm at work now, but this evening i will post my code to help.