115 lines
No EOL
2.8 KiB
C++
115 lines
No EOL
2.8 KiB
C++
#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); }
|
|
|
|
std::string format_float(double d, int precision)
|
|
{
|
|
std::stringstream sstream;
|
|
|
|
sstream << d;
|
|
sstream.precision(precision);
|
|
|
|
return sstream.str();
|
|
}
|
|
|
|
// RFServerPlugin class
|
|
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)
|
|
{
|
|
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);
|
|
}
|
|
|
|
void RFServerPlugin::UpdateScoring(const ScoringInfoV01 &info)
|
|
{
|
|
std::string msg = "[SCORE;";
|
|
msg += info.mMaxLaps + ";";
|
|
msg += format_float(info.mLapDist, 1) + ";";
|
|
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);
|
|
}
|
|
|
|
bool RFServerPlugin::AccessPitMenu(PitMenuV01 &info)
|
|
{
|
|
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);
|
|
|
|
return false;
|
|
} |