mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-07-01 23:35:41 +00:00
Auto name request + parser
This commit is contained in:
parent
b5dbb70104
commit
d368b154c2
@ -34,9 +34,7 @@ void SendToAll(ENetHost *server,ENetEvent event){
|
||||
}
|
||||
|
||||
void OnConnect(ENetPeer*peer){
|
||||
ENetPacket* packet = enet_packet_create ("NameRequest", //Send A Name Request to the Client
|
||||
strlen ("NameRequest") + 1,
|
||||
ENET_PACKET_FLAG_RELIABLE); //Create A reliable packet using the data
|
||||
ENetPacket* packet = enet_packet_create ("NR", 3,ENET_PACKET_FLAG_RELIABLE); //Create A reliable packet using the data
|
||||
enet_peer_send(peer, 0, packet);
|
||||
std::cout << "ID : " << peer->serverVehicleID << std::endl;
|
||||
}
|
||||
|
@ -11,6 +11,16 @@
|
||||
void Respond(const std::string& MSG, ENetPeer*peer);
|
||||
void ParseData(ENetPacket*packet, ENetPeer*peer){
|
||||
std::string Packet = (char*)packet->data;
|
||||
if(Packet == "p"){Respond("p",peer);return;}
|
||||
char Code = Packet.at(0),SubCode = 0;
|
||||
if(Packet.length() > 1)SubCode = Packet.at(1);
|
||||
switch (Code) {
|
||||
case 'p':
|
||||
Respond("p",peer);
|
||||
return;
|
||||
case 'N':
|
||||
if(SubCode == 'R')peer->Name = (void *)Packet.substr(2).c_str();
|
||||
std::cout << "Name : " << (char *)peer->Name << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "Data : " << Packet << std::endl;
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ int PlayerCount = 0;
|
||||
|
||||
int FindID(ENetHost *server,ENetPeer*peer){
|
||||
int OpenID = 1;
|
||||
bool Found = false;
|
||||
bool Found;
|
||||
do {
|
||||
Found = true;
|
||||
for (int i = 0; i < server->connectedPeers; i++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user