Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 12:52

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Split Function für Packets?

Discussion on Split Function für Packets? within the C/C++ forum part of the Coders Den category.

Reply
 
Old   #1
 
Mr.Zoey's Avatar
 
elite*gold: 0
Join Date: Sep 2012
Posts: 774
Received Thanks: 228
Question Split Function für Packets?

Hallo ich brauch mal eure hilfe

Also ich müsste das:
Code:
4000 packet1 4001 packet2 4003 packet3
zu das haben:
Code:
4000 packet1
4001 packet2
4003 packet3
Ich schaff es aber einfach nicht ;(
Mr.Zoey is offline  
Old 10/06/2012, 14:11   #2
 
elite*gold: 42
Join Date: Jun 2008
Posts: 5,426
Received Thanks: 1,888
regex.
MoepMeep is offline  
Old 10/06/2012, 14:51   #3
 
elite*gold: 5
Join Date: Sep 2006
Posts: 385
Received Thanks: 218
Code:
#include <string>
#include <sstream>
#include <iostream>

struct PacketInfo
{
	unsigned long opcode;
	std::string name;
};


std::stringstream& operator>>(std::stringstream& ss, PacketInfo& packetinfo)
{
	ss >> packetinfo.opcode;
	ss >> packetinfo.name;

	return ss;
}



int main()
{
	std::string stuff = "123 packet1 234 packet2 345 packet3 456 packet4";
	std::stringstream ss;
	ss << stuff;

	PacketInfo packetinfo;
	while(ss >> packetinfo)
		std::cout << packetinfo.opcode << " " << packetinfo.name << std::endl;
}
Aber nur weil heute internationaler Copy/Paste Tag ist!
Nightblizard is offline  
Old 10/06/2012, 23:32   #4
 
elite*gold: 0
Join Date: Dec 2011
Posts: 26
Received Thanks: 2
Dass das mit StringStreams so einfach geht, wusst ich noch gar nicht. Bisher habe ich für so etwas eine kleine Funktion geschrieben, die jeweils das nächste Leerzeichen sucht. Das wäre eigentlich auch eine ganz gute Übung, für alle, die noch nicht so viel mit strings gearbeitet haben.
daemon7777 is offline  
Old 10/07/2012, 15:49   #5
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
Quote:
Originally Posted by Nightblizard View Post
Code:
#include <string>
#include <sstream>
#include <iostream>

struct PacketInfo
{
	unsigned long opcode;
	std::string name;
};


std::stringstream& operator>>(std::stringstream& ss, PacketInfo& packetinfo)
{
	ss >> packetinfo.opcode;
	ss >> packetinfo.name;

	return ss;
}



int main()
{
	std::string stuff = "123 packet1 234 packet2 345 packet3 456 packet4";
	std::stringstream ss;
	ss << stuff;

	PacketInfo packetinfo;
	while(ss >> packetinfo)
		std::cout << packetinfo.opcode << " " << packetinfo.name << std::endl;
}
Aber nur weil heute internationaler Copy/Paste Tag ist!
I tryed it on my server and don't work..

><
ernilos is offline  
Old 10/07/2012, 19:04   #6
 
elite*gold: 5
Join Date: Sep 2006
Posts: 385
Received Thanks: 218
Well, then you're doing it wrong. The incoming string has to be in this format:
Code:
number<whitespace>name<whitespace>number<whitespace>string ...
Your code is needed in order to give further details.
Nightblizard is offline  
Old 10/08/2012, 18:34   #7
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
I tryed to write my own function
Code:
std::vector<std::string> splitPacket(string str)
{
	int temp;
	int cont;
	int stemp;
	std::vector<std::string> Packet = split(str,' ');
	std::vector<std::string> rPacket;
	temp = atoi(Packet[0].c_str());
	for(int i = 1; i < rPacket.size(); i++)
	{
		stemp = atoi(Packet[i].c_str());
		if(temp == stemp +1)
		{
			cont++;
			temp++;
		}
		else
		{
			cout << Packet[i].c_str() << endl;
			rPacket[cont] += Packet[i];
		}
	}
	return rPacket;
}
but don't works.. ><
ernilos is offline  
Old 10/08/2012, 20:41   #8
 
elite*gold: 5
Join Date: Sep 2006
Posts: 385
Received Thanks: 218
This doesn't even look close to the code I've posted...
Why are you doing it this way? It looks ugly as hell, is bug prone and not easy maintainable.

Furthermore, atoi is old C rubbish and not safe at all. You sould use stringstreams for that aswell!
Doing so will allow you stuff like this:


This is by far the better solution.
Nightblizard is offline  
Reply


Similar Threads Similar Threads
[Release] +5500 Packets structure , client/packets constants
10/07/2012 - CO2 PServer Guides & Releases - 10 Replies
edit : if u know nothing about packets go to this post first explaining what is packets , and explaining a packet with details and everything http://www.elitepvpers.com/forum/co2-pserver-disc ussions-questions/2162344-packets-packets-packets. html#post19074533 i start making my very own packet structure to use them on my new proxy but i thought of ripping them from the source so yeah the following packets is ripped of trinity base source right now im just providing the packets structure...
Replace and Split...
08/29/2012 - C/C++ - 3 Replies
I'm fairly new in c, and I have two questions. 1. How I can replace letters in a variable? (login_packet) (~ to nothing) 2. How I can split the var login_packet? (with " ") Thanks ..
[Packets] Wie änder ich flyff packets?
07/16/2011 - Flyff Private Server - 19 Replies
HeyHo, Ich würde sehr gerne wissen wie man die Flyff Packets ändert... ich denke mal Zahlen ändern werden nicht ausreichen oder?
gc split up
12/02/2010 - Grand Chase - 6 Replies
im confused i heard somethign about gc spliting up like with the chars and all but i dnt understand it how does it work and all ? its not comming anytime soon like in a month or so but hard to picture it
Want to split Mbot
12/27/2009 - Silkroad Online - 11 Replies
What the title says, I pay half you pay half, and we both get to use it since each mbot allows 2 PC to use it and each PC can open 3 windows at a time. if your interested I accept only paypal, So leave a message and we can continue conversation in PM. http://www.elitepvpers.com/forum/foreign-sro-hacks -bots-cheats-exploits/303945-csro-mbot-paid-bot.ht ml for more info. I was told it was about 15 USD total so 7.50 a person. If you need some proof that I wont scam, then ask slimshady, he can...



All times are GMT +2. The time now is 12:52.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.