Skip to content

Commit

Permalink
Initial OS support.
Browse files Browse the repository at this point in the history
  • Loading branch information
UnrealIncident committed Nov 6, 2013
1 parent 3b98a64 commit aa62a02
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 3 deletions.
34 changes: 32 additions & 2 deletions Sources/Client/NetClient.cpp
Expand Up @@ -83,7 +83,11 @@ namespace spades {
PacketTypeWeaponReload = 28, // C2S2P
PacketTypeChangeTeam = 29, // C2S2P
PacketTypeChangeWeapon = 30, // C2S2P

PacketTypeHandShakeInit = 31, // S2C
PacketTypeHandShakeReturn = 32, // C2S
PacketTypeVersionGet = 33, // S2C
PacketTypeVersionSend = 34, // C2S

};
class NetPacketReader {
std::vector<char> data;
Expand Down Expand Up @@ -1427,6 +1431,12 @@ namespace spades {
//p->SetWeaponType(wType);
}
break;
case PacketTypeHandShakeInit:
SendHandShakeValid(reader.ReadInt());
break;
case PacketTypeVersionGet:
SendVersion();
break;
default:
printf("WARNING: dropped packet %d\n", (int)reader.GetType());
reader.DumpDebug();
Expand Down Expand Up @@ -1682,7 +1692,27 @@ namespace spades {
wri.Write((uint8_t)GetLocalPlayer()->GetId());
wri.Write((uint8_t)team);
enet_peer_send(peer, 0, wri.CreatePacket());

}


void NetClient::SendHandShakeValid(int challenge) {
SPADES_MARK_FUNCTION();
NetPacketWriter wri(PacketTypeHandShakeReturn);
wri.Write((uint32_t)challenge);
SPLog("Sending hand shake back.");
enet_peer_send(peer, 0, wri.CreatePacket());
}

void NetClient::SendVersion() {
SPADES_MARK_FUNCTION();
NetPacketWriter wri(PacketTypeVersionSend);
wri.Write((uint8_t)'o');
wri.Write((uint8_t)OpenSpades_VERSION_MAJOR);
wri.Write((uint8_t)OpenSpades_VERSION_MINOR);
wri.Write((uint8_t)OpenSpades_VERSION_REVISION);
wri.Write(VersionInfo::GetVersionInfo());
SPLog("Sending version back.");
enet_peer_send(peer, 0, wri.CreatePacket());
}

void NetClient::MapLoaded() {
Expand Down
5 changes: 4 additions & 1 deletion Sources/Client/NetClient.h
Expand Up @@ -23,8 +23,10 @@

#include <string>
#include <vector>
#include <OpenSpades.h>
#include <Core/ServerAddress.h>
#include <Core/Math.h>
#include <Core/VersionInfo.h>
#include "PhysicsConstants.h"
#include "Player.h"

Expand Down Expand Up @@ -128,7 +130,8 @@ namespace spades {
void SendChat(std::string, bool global);
void SendWeaponChange(WeaponType);
void SendTeamChange(int team);

void SendHandShakeValid(int challenge);
void SendVersion();
};
}
}
14 changes: 14 additions & 0 deletions Sources/Core/VersionInfo.cpp
@@ -0,0 +1,14 @@
#include "VersionInfo.h"

std::string VersionInfo::GetVersionInfo()
{
#if defined __linux__
return std::string("Linux");
#elif TARGET_OS_MAC
return std::string("Mac OS X");
#elif defined _WIN32 || defined _WIN64
return std::string("Windows");
#else
return std::string("Unknown OS");
#endif
}
7 changes: 7 additions & 0 deletions Sources/Core/VersionInfo.h
@@ -0,0 +1,7 @@
#include <string>

class VersionInfo
{
public:
static std::string GetVersionInfo();
};

0 comments on commit aa62a02

Please sign in to comment.