Game server admin's helping the community setup and maintain great dedicated game servers.
----Home----Submit News ----Forum--------Guides----


Go Back   FPSadmin.com > BattleField > BattleField 3 > BF3 Remote Admin Tool Support

Reply
 
Thread Tools Display Modes
  #16  
Old 02-02-2012, 05:40 PM
PapaCharlie9's Avatar
PapaCharlie9 PapaCharlie9 is offline
Senior Member
 
Join Date: Jan 2011
Posts: 155
Rep Power: 7
PapaCharlie9 is on a distinguished road
Quote:
Originally Posted by JogDiveZero View Post
I see the problem theoretical youīre talking about. But it has no effect on the code right now
If I had a dime for every software engineer that told me, "but it works ... you are worrying for nothing," I'd be a millionaire. If I bet that software engineer a $100 that their code "that works" would eventually break down someplace and cause a problem, I'd be a billionaire.

Quoted for truth:
Quote:
Originally Posted by Kalms View Post
That way lies madness and bugs that are difficult to track down.
Don't use string for an array of bytes that may have zero as a valid value. Das ist ganz, ganz schlecht!
Reply With Quote
  #17  
Old 02-02-2012, 06:05 PM
JogDiveZero JogDiveZero is offline
Member
 
Join Date: Jan 2012
Posts: 64
Rep Power: 6
JogDiveZero is on a distinguished road
std::string can handle 0 bytes and itīs used in a bunch cases. In Scott Meyers latest C++ book is no word about not using it. I tested the code and it handled 0 bytes. I agree that old c-string structures canīt handle it.

If someone use this:
Code:
std::string s = "i am a string"; 
unsigned int len = strlen( s.c_str() );
....this will fail with 0 bytes in the string. Next question is why someone mix 2 diffrent languages. std::string can use the .size() function.


This can be a whole workaround to avoid string conflicts within the SequenceID if someone doesnīt trust:
Code:
std::vector<char> Buffer; 
std::string Word; 
 
Buffer.push_back( static_cast<char>( SequenceID & 0xff ) ); 
Buffer.push_back( static_cast<char>( SequenceID >> 8) & 0xff ); 
Buffer.push_back( static_cast<char>( SequenceID >> 16) & 0xff ); 
Buffer.push_back( static_cast<char>( SequenceID >> 24) & 0xff ); 
Buffer.insert( Buffer.end(), Word.begin(), Word.end() );


Thanks for your words guys!
Reply With Quote
  #18  
Old 02-02-2012, 06:57 PM
TimSad's Avatar
TimSad TimSad is offline
Member
 
Join Date: Nov 2008
Posts: 75
Rep Power: 9
TimSad is on a distinguished road
Awesome! I finally got my packet encoding to work! All I need to do is use it with proper memory management and I am good. The return value is for the Winsock send function to tell it how many bytes I am sending. I could access that if I made an object from a Packet class. I'll do that later...

Code:
unsigned int encodePacket(unsigned int seqNum, const vector<string>& words, char*& packet)
{
  ///// Initializing the packet content /////

  unsigned int packetSequence;

  // packetSequence = the sequence number in this command/response pair
  // This is a bitwise AND operation - Let's say the current seqNum is 3 (packetSequence = (0000 0000 0000 0000 0000 0000 0000 0011 & 0011 1111 1111 1111 1111 1111 1111 1111) = 0000 0000 0000 0000 0000 0000 0000 0011)
  packetSequence = seqNum & 0x3fffffff;

  // performs bitwise OR operation on packetSequence to signify that this packet originated on the client (Bit 31 = 1).
  // (packetSequence = (0000 0000 0000 0000 0000 0000 0000 0011 | 1000 0000 0000 0000 0000 0000 0000 0000) = 1000 0000 0000 0000 0000 0000 0000 0011)
  packetSequence |= 0x80000000;

  unsigned int packetSize;
  packetSize = 4 + 4 + 4; // packetSize = packet Sequence uInt + packet Size uInt + packet NumWords uInt

  // sum up the rest of the pack size reflected by Words
  vector<string>::const_iterator it;
  for(it = words.begin(); it != words.end(); it++)
  {
    packetSize += 4; // packetSize = packetSize + current Word size uInt
    packetSize += it->size(); // packetSize = packetSize + number of bytes in current Word
    packetSize += 1; // packetSize = packetSize + the 1 byte from the Word's single terminating char
  }

  unsigned int packetNumWords;
  packetNumWords = words.size(); // packetNumWords = the number of elements in the vector of words that was passed as a parameter


  ///// Constructing the packet /////

  char* encodedPacket = new char[packetSize];

  char* bytePtr = (char*)&packetSequence;
  for (int i = 0; i < sizeof(packetSequence); i++)
  {
    memcpy((encodedPacket + i), (bytePtr + i), 1);
  }

  bytePtr = (char*)&packetSize;
  for (int i = 0; i < sizeof(packetSize); i++)
  {
    memcpy((encodedPacket + i + 4), (bytePtr + i), 1);
  }

  bytePtr = (char*)&packetNumWords;
  for (int i = 0; i < sizeof(packetNumWords); i++)
  {
    memcpy((encodedPacket + i + 8), (bytePtr + i), 1);
  }

  int destinationByte = 12;
  for(it = words.begin(); it != words.end(); it++)
  {
    unsigned int currentWordSize = it->size();
    char* currentWord = new char[currentWordSize];
    strncpy(currentWord, (*it).c_str(), currentWordSize);
    char terminatingChar = '\0';

    bytePtr = (char*)&currentWordSize;
    for (int i = 0; i < sizeof(currentWordSize); i++)
    {
      memcpy((encodedPacket + destinationByte), (bytePtr + i), 1);
      destinationByte++;
    }

    bytePtr = currentWord;
    memcpy((encodedPacket + destinationByte), bytePtr, currentWordSize);
    destinationByte += currentWordSize;

    bytePtr = &terminatingChar;
    memcpy((encodedPacket + destinationByte), bytePtr, 1);
    destinationByte++;
  }

  packet = &encodedPacket[0];

  return packetSize;
}
__________________

Reply With Quote
  #19  
Old 02-02-2012, 07:25 PM
Kalms Kalms is offline
Senior Member
 
Join Date: Feb 2010
Posts: 262
Rep Power: 8
Kalms is on a distinguished road
Yes - it works - as long as you never try to do C-style operations on the string. I was not fully aware of this (I thought it was undefined and thus depended on the specific STL implementation), so thank you for convincing me to read up on it.


But you will confuse other people. What if someone else is to work with your code? 99% of the C++ code out there in the world is written with the assumption that you can use the c_str() interchangeably. This is what people are used to, and thus someone else working on your codebase in the future may introduce bugs because they don't understand that works in nearly all other code on the planet doesn't work in some parts of this codebase.

And you may face a similar problem when interfacing with others' code. You're saying "so make sure to only use C++ operations" but in any large enough project you will have to go between C and C++ operations in places. Now you'll probably not have that particular problem in this context. I'm mainly yapping because it goes against some principles of mine.


In fact I feel so strongly about it that I spent yesterday evening and most of today (I've been home ill) implementing an RCON communications library + a remote console in C++ myself. See this post: FrostbiteRcon library in C++

No comments nor docs, and there are certainly some usability problems with the console app itself, but you can't expect much more than this from 12 hours worth of coding.
Reply With Quote
  #20  
Old 02-03-2012, 06:48 AM
JogDiveZero JogDiveZero is offline
Member
 
Join Date: Jan 2012
Posts: 64
Rep Power: 6
JogDiveZero is on a distinguished road
Thanks in advance Mr Kalms and i wish you "gute Besserung"

PapaCharlie, my pennys please :-)
Reply With Quote
  #21  
Old 02-03-2012, 07:02 PM
TimSad's Avatar
TimSad TimSad is offline
Member
 
Join Date: Nov 2008
Posts: 75
Rep Power: 9
TimSad is on a distinguished road
Quick question... How do you receive server events?

EDIT: Ahh! Found the answer to my question!... admin.eventsEnabled true
__________________


Last edited by TimSad; 02-03-2012 at 08:06 PM.
Reply With Quote
  #22  
Old 02-05-2012, 10:23 AM
JogDiveZero JogDiveZero is offline
Member
 
Join Date: Jan 2012
Posts: 64
Rep Power: 6
JogDiveZero is on a distinguished road
@Tim Sad:

I debuged and optimized my build and it runs very smooth. In the next weeks i will stuff all server.vars and config stuff into my rcon client. If you have any questions - feel free

P.S my rcon client is a non public software. only for our gaming community
Attached Thumbnails
Click image for larger version

Name:	YARCC.jpg
Views:	361
Size:	141.7 KB
ID:	331  
Reply With Quote
  #23  
Old 02-06-2012, 04:58 AM
TimSad's Avatar
TimSad TimSad is offline
Member
 
Join Date: Nov 2008
Posts: 75
Rep Power: 9
TimSad is on a distinguished road
Very nice JogDive! I just completed a chat program that I have connecting to my Operation Metro server...



Attached Thumbnails
Click image for larger version

Name:	tim_bf3_chat_prog.jpg
Views:	400
Size:	187.4 KB
ID:	332  
__________________

Reply With Quote
  #24  
Old 02-06-2012, 08:21 AM
JogDiveZero JogDiveZero is offline
Member
 
Join Date: Jan 2012
Posts: 64
Rep Power: 6
JogDiveZero is on a distinguished road
Hey Tim!
i think its a good idea that you filter the server.onchat messages out.



My filters working good for now. I added a download function to get the running maplist, edit maps with mode and rounds, upload the setup:
Attached Thumbnails
Click image for larger version

Name:	YARCC.jpg
Views:	364
Size:	161.6 KB
ID:	333  
Reply With Quote
  #25  
Old 02-07-2012, 05:47 PM
TimSad's Avatar
TimSad TimSad is offline
Member
 
Join Date: Nov 2008
Posts: 75
Rep Power: 9
TimSad is on a distinguished road
I could still acquire much more skill and knowledge to make this program much more efficient and effective but this is what I've come up with...
Attached Thumbnails
Click image for larger version

Name:	bf3_chat_image.jpg
Views:	337
Size:	78.1 KB
ID:	334   Click image for larger version

Name:	bf3_chat_image2.jpg
Views:	343
Size:	185.2 KB
ID:	335  
__________________

Reply With Quote
  #26  
Old 02-14-2012, 03:07 PM
JogDiveZero JogDiveZero is offline
Member
 
Join Date: Jan 2012
Posts: 64
Rep Power: 6
JogDiveZero is on a distinguished road
My app is ready and debugged for now. I will work on it if i got new ideas






Reply With Quote
  #27  
Old 03-13-2014, 04:22 PM
VuurAngel VuurAngel is offline
Junior Member
 
Join Date: Mar 2014
Posts: 1
Rep Power: 0
VuurAngel is on a distinguished road
@TimSad Nice work!

I did uses, you encodePacket to send Packet, But can you help me to Decode the Packets? I did tray alot, im new at C++ i don't need a big code or stuff..... but please can you help me on the road?

Ty
VuurAngel
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 06:35 AM.


Powered by: vBulletin Copyright ©2000, Jelsoft Enterprises Ltd.