translator necessary :\
by Matias Pecile · in Technical Issues · 07/30/2001 (2:57 pm) · 7 replies
can anyone translate this code into VB code??? this is C code in a .h file:
/**************************************************/
struct q_packet {
unsigned char flag1;
unsigned char flag2;
unsigned short length;
unsigned char op_code;
unsigned char data[19];
};
#define Q_HEADER_LEN 5
/*
struct {
unsigned char flag1;
unsigned char flag2;
unsigned short length;
unsigned char op_code;
char name[6];
unsigned char version;
};
*/
#define Q_FLAG1 0x80
#define Q_FLAG2 0x00
#define Q_CCREQ_SERVER_INFO 0x02
#define Q_CCREQ_PLAYER_INFO 0x03
#define Q_CCREQ_RULE_INFO 0x04
/* The \003 below is the protocol version */
#define Q_SERVERINFO_LEN 12
struct q_packet q_serverinfo =
{ Q_FLAG1, Q_FLAG2, Q_SERVERINFO_LEN, Q_CCREQ_SERVER_INFO, "QUAKE\000\003" };
struct q_packet q_rule = {Q_FLAG1,Q_FLAG2, 0, Q_CCREQ_RULE_INFO, ""};
struct q_packet q_player = {Q_FLAG1,Q_FLAG2, 6, Q_CCREQ_PLAYER_INFO, ""};
/**************************************************/
any help would be extremely apreciated
EDIT: I just noticed this is the 1000th thread, do I get a price or something??? :P I am proud of myself
/**************************************************/
struct q_packet {
unsigned char flag1;
unsigned char flag2;
unsigned short length;
unsigned char op_code;
unsigned char data[19];
};
#define Q_HEADER_LEN 5
/*
struct {
unsigned char flag1;
unsigned char flag2;
unsigned short length;
unsigned char op_code;
char name[6];
unsigned char version;
};
*/
#define Q_FLAG1 0x80
#define Q_FLAG2 0x00
#define Q_CCREQ_SERVER_INFO 0x02
#define Q_CCREQ_PLAYER_INFO 0x03
#define Q_CCREQ_RULE_INFO 0x04
/* The \003 below is the protocol version */
#define Q_SERVERINFO_LEN 12
struct q_packet q_serverinfo =
{ Q_FLAG1, Q_FLAG2, Q_SERVERINFO_LEN, Q_CCREQ_SERVER_INFO, "QUAKE\000\003" };
struct q_packet q_rule = {Q_FLAG1,Q_FLAG2, 0, Q_CCREQ_RULE_INFO, ""};
struct q_packet q_player = {Q_FLAG1,Q_FLAG2, 6, Q_CCREQ_PLAYER_INFO, ""};
/**************************************************/
any help would be extremely apreciated
EDIT: I just noticed this is the 1000th thread, do I get a price or something??? :P I am proud of myself
About the author
#2
07/30/2001 (6:40 pm)
well, this isn't even mine, I am trying to help another guy out, but he is making a software very similar to mplayer/gamespy and he is making it VB, I believe that with that piece of code that is in C he can display the properties of a running server in real time in the software. That is why he wanted to know, and I am only a middle man trying to help :\ If this isn't possible to do, then I guess we will have to find another way of coding this, but if you know how to translate it, I think my friend would be very happy
#3
Don't know if that'll help or not, but that's as literal translation as I could figure.
07/31/2001 (5:58 am)
I'd question the usefulness of this (as well as my own ability to translate C into VB :)) but here's my best try:'************************************************** Public Type q_packet flag1 As Integer flag2 As Integer length As Integer op_code As Integer data As String * 19 End Type Public Q_HEADER_LEN As Integer Q_HEADER_LEN = 5 'Maybe my C is a bit rusty, but why would you declare 'An unnamed struct? It's illegal in VB, in any case. Public Type unnamed flag1 As Integer flag2 As Integer length As Integer op_code As Integer name as String * 6 version as Integer End Type Public Q_FLAG1 as Integer Q_FLAG1 = &H80 Public Q_FLAG2 as Integer Q_FLAG2 = &H00 Public Q_CCREQ_SERVER_INFO as Integer Q_CCREQ_SERVER_INFO = &H02 Public Q_CCREQ_PLAYER_INFO as Integer Q_CCREQ_PLAYER_INFO = &H03 Public Q_CCREQ_RULE_INFO as Integer Q_CCREQ_RULE_INFO = &H04 ' The [[60c1d4df86571]]3 below is the protocol version Public Q_SERVERINFO_LEN as Integer Q_SERVERINFO_LEN = 12 Dim q_serverinfo As q_packet q_serverinfo.flag1 = hex(Q_FLAG1) q_serverinfo.flag2 = hex(Q_FLAG2) q_serverinfo.length = Q_SERVERINFO_LEN q_serverinfo.op_code = hex(Q_CCREQ_SERVER_INFO) q_serverinfo.data = "QUAKE[[60c1d4df86571]]0[[60c1d4df86571]]3" Dim q_rule As q_packet q_rule.flag1 = hex(Q_FLAG1) q_rule.flag2 = hex(Q_FLAG2) q_rule.length = 0 q_rule.op_code = hex(Q_CCREQ_RULE_INFO) q_rule.data = "" Dim q_player As q_packet q_player.flag1 = hex(Q_FLAG1) q_player.flag2 = hex(Q_FLAG2) q_player.length = 6 q_player.op_code = hex(Q_CCREQ_PLAYER_INFO) q_player.data = "" '**************************************************
Don't know if that'll help or not, but that's as literal translation as I could figure.
#4
07/31/2001 (6:34 am)
Type q_packet
flag1 As Byte
flag2 As Byte
length As Single
op_code As Byte
data As String
End Type
Q_HEADER_LEN = 5
Q_FLAG1 = &H08
Q_FLAG2 = &H00
Q_CCREQ_SERVER_INFO = &H02
Q_CCREQ_PLAYER_INFO = &H03
Q_CCREQ_RULE_INFO = &H04
Q_SERVERINFO_LEN = 12
Dim q_serverinfo, q_rule, q_player As q_packet
q_serverinfo.flag1 = Q_FLAG1
q_serverinfo.flag2 = Q_FLAG2
q_serverinfo.length = Q_SERVERINFO_LEN
q_serverinfo.op_code = Q_CCREQ_SERVER_INFO
q_serverinfo.data = "QUAKE[[60c1d4df970da]]0[[60c1d4df970da]]3"
q_rule.flag1 = Q_FLAG1
q_rule.flag2 = Q_FLAG2
q_rule.length = Q_SERVERINFO_LEN
q_rule.op_code = Q_CCREQ_RULE_INFO
q_rule.data = ""
q_player.flag1 = Q_FLAG1
q_player.flag2 = Q_FLAG2
q_player.length = Q_SERVERINFO_LEN
q_player.op_code = Q_CCREQ_PLAYER_INFO
q_player.data = ""
#5
Just as a note:
Dim q_serverinfo, q_rule, q_player As q_packet
That will result in q_serverinfo and q_rule being variants, with only q_player being a q_packet. VB is funny like that, you've got to give each variable it's own As statement.
07/31/2001 (8:55 am)
I thought about making it look pretty like that, but decided to go for a silly literal translation with all the definitions and initializations in the same place.Just as a note:
Dim q_serverinfo, q_rule, q_player As q_packet
That will result in q_serverinfo and q_rule being variants, with only q_player being a q_packet. VB is funny like that, you've got to give each variable it's own As statement.
#6
Public Type q_packet
flag1 As Byte
flag2 As Byte
length As Single
op_code As Byte
data As String
End Type
' the equivalent of #define in VB is Public Const
Public Const Q_HEADER_LEN As Integer = 5
Public Const Q_FLAG1 As Byte = &H80
Public Const Q_CCREQ_SERVER_INFO As Byte = &H2
Public Const Q_CCREQ_PLAYER_INFO As Byte = &H3
Public Const Q_CCREQ_RULE_INFO As Byte = &H4
Public Const Q_SERVERINFO_LEN As Integer = 12
Public q_serverinfo As q_packet
Public q_rule As q_packet
Public q_player As q_packet
' AFAIK you have to init the types within a procedure...
Public Sub Init()
With q_serverinfo
.flag1 = Q_FLAG1
.flag2 = Q_FLAG2
.length = Q_SERVERINFO_LEN
.op_code = Q_CCREQ_SERVER_INFO
.data = "QUAKE\000\003"
End With
' similar for the other 2
End Sub
07/31/2001 (10:04 am)
Ok, here's my take... what the heck :)Public Type q_packet
flag1 As Byte
flag2 As Byte
length As Single
op_code As Byte
data As String
End Type
' the equivalent of #define in VB is Public Const
Public Const Q_HEADER_LEN As Integer = 5
Public Const Q_FLAG1 As Byte = &H80
Public Const Q_CCREQ_SERVER_INFO As Byte = &H2
Public Const Q_CCREQ_PLAYER_INFO As Byte = &H3
Public Const Q_CCREQ_RULE_INFO As Byte = &H4
Public Const Q_SERVERINFO_LEN As Integer = 12
Public q_serverinfo As q_packet
Public q_rule As q_packet
Public q_player As q_packet
' AFAIK you have to init the types within a procedure...
Public Sub Init()
With q_serverinfo
.flag1 = Q_FLAG1
.flag2 = Q_FLAG2
.length = Q_SERVERINFO_LEN
.op_code = Q_CCREQ_SERVER_INFO
.data = "QUAKE\000\003"
End With
' similar for the other 2
End Sub
#7
07/31/2001 (12:31 pm)
thanks for all the help guys, we're testing the code now, I'll post back later today and tell you if they work. But thanks very much in advance
William Finlayson
I'm a bit rusty on my VB but the structs should be quite easy to turn into user defined types. As for the defines, what's the point without the code it's supposed to be included in? I just don't see what you could do with it when translated.
If you could provide a better explanation as to what you are trying to do then maybe I could help.