hello,
can someone help me to implement these commands in C#? or other but in the same context
static string fact = "";
fact = find_str_from_to2(responseFromServer, ">", "-1<");
if (fact = 1)
then (comp = 11955|708);
else
if (fact = 2)
then (comp = 9080|55);
else
if (fact = 3)
then (comp = 1085|708); // update..
fact must me string, because i'm getting he's value from a website....
and i need to use other string.. but i need these if conditions..
ty.
Loading

VulpesRank #55 · 29.2K reputationPosted Dec 13, 2011, 7:55 AM EST
andrei hooba67 reputationPosted Dec 13, 2011, 8:04 AM EST
for each fact must be different comp ..
VulpesRank #55 · 29.2K reputationPosted Dec 13, 2011, 8:34 AM EST
andrei hooba67 reputationPosted Dec 13, 2011, 11:31 AM EST
one more thing..
i send this packet
IPAddress host = IPAddress.Parse(sGameServerIp);
IPEndPoint hostep = new IPEndPoint(host, 8080);
Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
sock.Connect(hostep);
}
catch (SocketException e)
{
sock.Close();
return;
}
try
{
sock.Send(Encoding.UTF8.GetBytes("LOGIN|" + ID + ClientVersion));
}
catch (SocketException e)
{
sock.Close();
return;
}
sock.Close();
and i receive this packet:
0|3|95|150|502|0|0|0|500|0|3|0|0|0|0|0|0.
0|TX|S|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0.
0|A|ITM|0|0|0|0|9|0|0|0|0|0|0|0|0|0|0|0.
0|E|0|0|0|50|0|0|0|0|0.
0|m|5|21000|13500.
and i don't know how to get some data's from these packets
for ex.: coord = find_str_from_to2(responseFromServer, "0|m|5|", ".");
and when i -> Console.WriteLine(coord); the console it write '-1' ... and not 21000|13500
ty
VulpesRank #55 · 29.2K reputationPosted Dec 14, 2011, 12:37 AM EST
andrei hooba67 reputationPosted Dec 14, 2011, 6:19 AM EST
static void getResponse(ref WebRequest reqPOST, ref WebResponse result, ref StreamReader reader, ref string responseFromServer)
{
result = reqPOST.GetResponse();
if (result.Headers.Get("Content-Encoding") != null && result.Headers.Get("Content-Encoding").ToLower() == "gzip")
reader = new System.IO.StreamReader(new GZipStream(result.GetResponseStream(), CompressionMode.Decompress));
else
reader = new System.IO.StreamReader(result.GetResponseStream());
responseFromServer = reader.ReadToEnd();
}
and here is find_str_from_to2 defined.
static string find_str_from_to2(string sMain, string sFrom, string sTo)
{
int iBegSubstr = sMain.IndexOf(sFrom);
if (iBegSubstr == -1) return "-1";
iBegSubstr += sFrom.Length;
int iEndSubstr = sMain.IndexOf(sTo, iBegSubstr);
if (iEndSubstr == -1) return "-1";
return sMain.Substring(iBegSubstr, iEndSubstr - iBegSubstr);
}
////
ok let me explain what the program should do.
access, let say the page, www.test.com -> login on this page -> get some datas from this page and after that send a login packet via send.Socket to some IP:8080 (which is taken from www.test.com page)..
ok the account it succesfully conected on that IP:8080 , but i dont know how get some datas from response...
maybe it's needed to create another 'responsefromserver' for the new ip ?
VulpesRank #55 · 29.2K reputationPosted Dec 14, 2011, 6:53 AM EST
andrei hooba67 reputationPosted Dec 14, 2011, 7:55 AM EST
andrei hooba67 reputationPosted Dec 15, 2011, 7:23 AM EST
LOGIN|uid|clientversion
.PNG
.
and i want to use this method:
string CrLf = ("\r\n");
try
{
string szData = ("LOGIN|" + uID + "|" + ClientVersion + CrLf + ".PNG" + CrLf +"." );
byte[] byData = System.Text.Encoding.UTF8.GetBytes(szData);
Int32 port = 8080;
TcpClient client = new TcpClient(sGameServerIp, port);
NetworkStream stream = client.GetStream();
stream.Write(byData, 0, byData.Length);
byData = new Byte[6144];
String responseData = String.Empty;
Int32 bytes = stream.Read(byData, 0, byData.Length);
responseData = System.Text.Encoding.ASCII.GetString(byData, 0, bytes);
Console.WriteLine("Received: {0}", responseData);
}
catch (SocketException e)
{
}
the problem is responseData , because it doesn't "catch" the entire packet received..
it "catch" only the first line...
if response is this:
0|TX|S|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0.
0|A|SET|1|1|1|1|1|1|1|1|1|1|1|0|0|1|1|2|3|1|1|0|0|1|0|1|1.
0|7|QUALITY_POIZONE|3.
the responseData gets only the 0|TX|S|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0.
how can i get the entire packet/s?
VulpesRank #55 · 29.2K reputationPosted Dec 15, 2011, 9:46 AM EST
andrei hooba67 reputationPosted Dec 15, 2011, 9:59 AM EST
0|TX|S|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0.
0|A|SET|
VulpesRank #55 · 29.2K reputationPosted Dec 15, 2011, 11:23 AM EST
If you do, I'd use BinaryWriter.Write to write the string to the NetworkStream and then call its Flush method to make sure nothing is left in the buffer.
andrei hooba67 reputationPosted Dec 15, 2011, 12:13 PM EST
anyway i fixed this issue.
but i got another :D
i've got this string
string resources = find_str_from_to2(responseData, "0|E|", "0|m|");
the response will be like this: 1|2|3|4|5|6|7|8|9
how can i split these values, and put those values in another strings?
to be like:
string a = 1;
..
string i = 9;
////////
i thought at something like the following method would work.. but...
string[] words = resources.Text.Split("|");
string a = words[0];
string b = words[1];
string c = words[2];
string d = words[3];
string e = words[4];
string f = words[5];
string g = words[6];
string h = words[7];
string i = words[8];
VulpesRank #55 · 29.2K reputationPosted Dec 15, 2011, 1:15 PM EST
string[] words = resources.Text.Split('|'); // single quotes around the |
andrei hooba67 reputationPosted Dec 15, 2011, 11:48 PM EST
string[] words = resources.Text.Split('|');
1: 'string' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
2: Cannot implicitly convert type 'char' to 'string'
VulpesRank #55 · 29.2K reputationPosted Dec 15, 2011, 11:53 PM EST
Change it to this and it should work:
string[] words = resources.Split('|');
andrei hooba67 reputationPosted Dec 16, 2011, 11:45 AM EST
but i got another issue :/
i have to send a packet to server.
the packet look like this:
T|13|3750
.
hex -> 54 7C 31 33 7C 33 37 35-30 0A 00
i defined a call:
string CrLf = ("\n");
string send = ("T|13|3750" + CrLf + ".");
byte[] sendit = System.Text.Encoding.UTF8.GetBytes(send);
stream.Write(sendit, 0, sendit.Length);
in ASCII code the packet looks like
T|13|3750
.
but in hex it looks like:
54 7C 31 33 7C 33 37 35-30 0A 2E
how can i send the required call , but with 00 instead of 2E ?
VulpesRank #55 · 29.2K reputationPosted Dec 17, 2011, 3:32 AM EST
andrei hooba67 reputationPosted Dec 17, 2011, 5:25 AM EST
thank you all.
topic can be closed now.