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
andrei hoobaPosted Dec 17, 2011, 10:25 AM
thank you all.
topic can be closed now.
VulpesPosted Dec 17, 2011, 8:32 AM
andrei hoobaPosted Dec 16, 2011, 4:45 PM
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 ?
VulpesPosted Dec 16, 2011, 4:53 AM
Change it to this and it should work:
string[] words = resources.Split('|');
andrei hoobaPosted Dec 16, 2011, 4:48 AM
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'
VulpesPosted Dec 15, 2011, 6:15 PM
string[] words = resources.Text.Split('|'); // single quotes around the |
andrei hoobaPosted Dec 15, 2011, 5:13 PM
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];
VulpesPosted Dec 15, 2011, 4:23 PM
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 hoobaPosted Dec 15, 2011, 2:59 PM
0|TX|S|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0.
0|A|SET|
VulpesPosted Dec 15, 2011, 2:46 PM
andrei hoobaPosted Dec 15, 2011, 12:23 PM
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?
andrei hoobaPosted Dec 14, 2011, 12:55 PM
VulpesPosted Dec 14, 2011, 11:53 AM
andrei hoobaPosted Dec 14, 2011, 11:19 AM
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 ?
VulpesPosted Dec 14, 2011, 5:37 AM
andrei hoobaPosted Dec 13, 2011, 4:31 PM
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
VulpesPosted Dec 13, 2011, 1:34 PM
andrei hoobaPosted Dec 13, 2011, 1:04 PM
for each fact must be different comp ..
VulpesPosted Dec 13, 2011, 12:55 PM