2022-02-09 13:27:02 +00:00
|
|
|
#include "RFServer.hpp" // corresponding header file
|
|
|
|
#include <math.h> // for atan2, sqrt
|
|
|
|
#include <stdio.h> // for sample output
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
// plugin information
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport)
|
|
|
|
const char *__cdecl GetPluginName() { return ("rF Server Plugin"); }
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport)
|
|
|
|
PluginObjectType __cdecl GetPluginType() { return (PO_INTERNALS); }
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport) int __cdecl GetPluginVersion() { return (7); } // InternalsPluginV07 functionality
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport)
|
|
|
|
PluginObject *__cdecl CreatePluginObject() { return ((PluginObject *)new RFServerPlugin); }
|
|
|
|
|
|
|
|
extern "C" __declspec(dllexport) void __cdecl DestroyPluginObject(PluginObject *obj) { delete ((RFServerPlugin *)obj); }
|
|
|
|
|
2022-02-09 14:10:58 +00:00
|
|
|
std::string format_float(double d, int precision)
|
|
|
|
{
|
|
|
|
std::stringstream sstream;
|
|
|
|
|
|
|
|
sstream << d;
|
|
|
|
sstream.precision(precision);
|
|
|
|
|
|
|
|
return sstream.str();
|
|
|
|
}
|
2022-02-09 13:27:02 +00:00
|
|
|
|
2022-02-09 14:10:58 +00:00
|
|
|
// RFServerPlugin class
|
2022-02-09 13:27:02 +00:00
|
|
|
RFServerPlugin::RFServerPlugin()
|
|
|
|
{
|
|
|
|
socket = new Socket(6262);
|
|
|
|
}
|
|
|
|
|
|
|
|
RFServerPlugin::~RFServerPlugin()
|
|
|
|
{
|
|
|
|
delete socket;
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::Startup(long version)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::Shutdown()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::StartSession()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::EndSession()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::EnterRealtime()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::ExitRealtime()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::UpdateTelemetry(const TelemInfoV01 &info)
|
|
|
|
{
|
2022-02-09 14:10:58 +00:00
|
|
|
std::string msg = "[TELEMETRY;";
|
|
|
|
msg += format_float(info.mElapsedTime, 3) + ";";
|
|
|
|
msg += format_float(info.mLapStartET, 3) + ";";
|
|
|
|
msg += info.mLapNumber + ";";
|
|
|
|
msg += format_float(100.0 * info.mFilteredThrottle, 1) + ";";
|
|
|
|
msg += format_float(100.0 * info.mFilteredBrake, 1) + ";";
|
|
|
|
msg += format_float(info.mFuel, 1) + ";";
|
|
|
|
msg += info.mScheduledStops;
|
|
|
|
msg += "]";
|
|
|
|
|
|
|
|
this->socket->send(msg);
|
2022-02-09 13:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RFServerPlugin::UpdateScoring(const ScoringInfoV01 &info)
|
|
|
|
{
|
2022-02-09 14:10:58 +00:00
|
|
|
std::string msg = "[SCORE;";
|
2022-02-09 13:27:02 +00:00
|
|
|
msg += info.mMaxLaps + ";";
|
|
|
|
msg += format_float(info.mLapDist, 1) + ";";
|
2022-02-09 14:10:58 +00:00
|
|
|
msg += format_float(info.mDarkCloud, 2) + ";";
|
|
|
|
msg += format_float(info.mRaining, 2) + ";";
|
|
|
|
msg += format_float(info.mAmbientTemp, 1) + ";";
|
|
|
|
msg += format_float(info.mTrackTemp, 1) + ";";
|
|
|
|
msg += format_float(info.mMinPathWetness, 2) + ";";
|
|
|
|
msg += format_float(info.mMaxPathWetness, 2) + ";";
|
|
|
|
msg += info.mNumVehicles + ";";
|
|
|
|
msg += info.mYellowFlagState + ";";
|
|
|
|
msg += info.mSectorFlag[0] + ";";
|
|
|
|
msg += info.mSectorFlag[1] + ";";
|
|
|
|
msg += info.mSectorFlag[2];
|
|
|
|
msg += "]";
|
|
|
|
|
|
|
|
this->socket->send(msg);
|
2022-02-09 13:27:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RFServerPlugin::AccessPitMenu(PitMenuV01 &info)
|
|
|
|
{
|
2022-02-09 14:10:58 +00:00
|
|
|
std::string msg = "[PIT;";
|
|
|
|
msg += info.mCategoryIndex + ";";
|
|
|
|
msg += std::string(info.mCategoryName) + ";";
|
|
|
|
msg += info.mChoiceIndex + ";";
|
|
|
|
msg += std::string(info.mChoiceString) + ";";
|
|
|
|
msg += info.mNumChoices;
|
|
|
|
msg += "]";
|
|
|
|
|
|
|
|
this->socket->send(msg);
|
|
|
|
|
2022-02-09 13:27:02 +00:00
|
|
|
return false;
|
|
|
|
}
|