Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 46 additions & 10 deletions src/core/fsnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,8 @@ void FsNetworkUser::Initialize(void)
controlShowUserNameReadBack=YSFALSE;
environmentReadBack=YSFALSE;
preparationReadBack=YSFALSE;

usingYSCE=YSFALSE; //Switch to decide whether to send them the new packets, if and when they come.
}


Expand Down Expand Up @@ -2550,7 +2552,7 @@ YSRESULT FsSocketServer::ReceiveLogOnUser(int clientId,int version,const char re

YSRESULT versionCheck;
versionCheck=YSERR;
if(version==YSFLIGHT_NETVERSION)
if(version==YSFLIGHT_NETVERSION || version >= 20150425)
{
versionCheck=YSOK;
}
Expand Down Expand Up @@ -3770,8 +3772,12 @@ YSRESULT FsSocketServer::ReceiveTextMessage(int clientId,unsigned char dat[],uns
}
}

YSRESULT FsSocketServer::ReceiveEnvironmentRequest(int clientId,unsigned char [],unsigned )
YSRESULT FsSocketServer::ReceiveEnvironmentRequest(int clientId,unsigned char dat[],unsigned packetLength )
{
if (packetLength>4){
//We've got a packet from a YSCE client.
user[clientId].usingYSCE=YSTRUE;
}
return SendEnvironment(clientId);
}

Expand Down Expand Up @@ -4203,6 +4209,7 @@ YSRESULT FsSocketServer::SendVersionNotify(int clientId)
ptr=dat;
FsPushInt(ptr,FSNETCMD_VERSIONNOTIFY);
FsPushInt(ptr,YSFLIGHT_NETVERSION);
FsPushInt(ptr,1); //Push a 1, this will let the client know if they're connecting to a YSCE server.
return SendPacket(clientId,ptr-dat,dat);
}
return YSOK;
Expand Down Expand Up @@ -4274,10 +4281,18 @@ YSRESULT FsSocketServer::SendEnvironment(int clientId)
YSBOOL fog;
double visibility;
unsigned flags;
int cloudLayerCount;
int version = 1;
if (user[clientId].usingYSCE == YSTRUE)
{
version = 2;
}


wind=sim->GetWeather().GetWind();
fog=sim->GetWeather().GetFog();
visibility=sim->GetWeather().GetFogVisibility();
cloudLayerCount = sim->GetWeather().GetCloudLayerCount();

flags=0;
if(fog==YSTRUE)
Expand Down Expand Up @@ -4344,13 +4359,23 @@ YSRESULT FsSocketServer::SendEnvironment(int clientId)

ptr=dat;
FsPushInt (ptr,FSNETCMD_ENVIRONMENT);
FsPushShort(ptr,1); // Version 1:Env, Flags, Wind, Visibility
FsPushShort(ptr,version); // Version 1:Env, Flags, Wind, Visibility
FsPushShort(ptr,(short)sim->GetEnvironment());
FsPushInt (ptr,flags);
FsPushFloat(ptr,(float)wind.x());
FsPushFloat(ptr,(float)wind.y());
FsPushFloat(ptr,(float)wind.z());
FsPushFloat(ptr,(float)visibility);

if (version==2){ //YSCE version, cloud layers.
FsPushInt(ptr,cloudLayerCount);
for (int i = 0; i < cloudLayerCount; i++){
const FsWeatherCloudLayer* layer;
sim->GetWeather().GetCloudLayer(i,layer);
FsPushInt(ptr, layer->y0);
FsPushInt(ptr, layer->y1);
}
}
return SendPacket(clientId,ptr-dat,dat);
}

Expand Down Expand Up @@ -4955,6 +4980,7 @@ FsSocketClient::FsSocketClient(const char username[],const int port,FsSimulation
sideWindowAssigned=YSFALSE;

reportedServerVersion=0;
ysceServer=YSFALSE;

svrUseMissile=YSTRUE;
svrUseUnguidedWeapon=YSTRUE;
Expand Down Expand Up @@ -5090,7 +5116,7 @@ YSRESULT FsSocketClient::Received(YSSIZE_T nBytes,unsigned char dat[])
ReceiveAssignSideWindow(cmdTop);
break;
case FSNETCMD_VERSIONNOTIFY:
ReceiveVersionNotify(cmdTop);
ReceiveVersionNotify(packetLength,cmdTop);
break;
case FSNETCMD_AIRCMD:
ReceiveAirCmd(cmdTop);
Expand Down Expand Up @@ -5718,9 +5744,10 @@ YSRESULT FsSocketClient::SendTextMessage(const char txt[])

YSRESULT FsSocketClient::SendEnvironmentRequest(void)
{
unsigned char dat[4];
unsigned char dat[8];
FsSetInt(dat,FSNETCMD_ENVIRONMENT);
return SendPacket(4,dat);
FsSetInt(dat+4,1); //Send a 1 to indicate that this a request from a YSCE client.
return SendPacket(8,dat);
}

YSRESULT FsSocketClient::SendResendJoinApproval(void)
Expand Down Expand Up @@ -6417,13 +6444,22 @@ YSRESULT FsSocketClient::ReceiveAssignSideWindow(unsigned char dat[])
return YSOK;
}

YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned char dat[])
YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned int packetLength, unsigned char dat[])
{
int svrVersion;

char str[256];

svrVersion=FsGetInt(dat+4);

const unsigned char *ptr=dat;
FsPopInt(ptr); // Skip FSNETCMD_VERSIONNOTIFY
svrVersion=FsPopInt(ptr);
printf("PacketLength is %d\n",packetLength);
if (packetLength>=8){
int ysceVersion=FsPopInt(ptr);
if (ysceVersion >0){
ysceServer=YSTRUE;
}
}

AddMessage("Version check");
sprintf(str," SERVER NET-VERSION : %d",svrVersion);
AddMessage(str);
Expand Down
4 changes: 3 additions & 1 deletion src/core/fsnetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class FsNetworkUser
YsArray <unsigned int> gndToSend,airToSend;
YSBOOL useMissileReadBack,useUnguidedWeaponReadBack,controlShowUserNameReadBack;
YSBOOL environmentReadBack,preparationReadBack;
YSBOOL usingYSCE;

YsArray <unsigned int> gndRmvToSend,airRmvToSend;
int joinSequence; // 0:Not in process 1:Waiting for Airplane Read Back 2:Waiting for SetPlayer Read Back
Expand Down Expand Up @@ -535,6 +536,7 @@ class FsSocketClient : public YsSocketClient, public FsClientVariable
YSBOOL connectionClosedByServer; // Will be set YSTRUE if the connection was closed from the server side.
int lastErrorFromServer;
unsigned int reportedServerVersion;
YSBOOL ysceServer;

FsSocketClient(const char username[],const int port,class FsSimulation *associatedSimulation,class FsNetConfig *cfg);

Expand Down Expand Up @@ -610,7 +612,7 @@ class FsSocketClient : public YsSocketClient, public FsClientVariable
YSRESULT ReceiveGetDamage(unsigned char dat[]);
YSRESULT ReceiveSetTestAutopilot(unsigned char dat[]);
YSRESULT ReceiveAssignSideWindow(unsigned char dat[]);
YSRESULT ReceiveVersionNotify(unsigned char dat[]);
YSRESULT ReceiveVersionNotify(unsigned int packetLength,unsigned char dat[]);
YSRESULT ReceiveAirCmd(unsigned char dat[]);
YSRESULT ReceiveGndCmd(unsigned char dat[]);
YSRESULT ReceiveTextMessage(unsigned char dat[]);
Expand Down
13 changes: 13 additions & 0 deletions src/core/fsweather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ int FsWeatherCloudLayer::CloudLayerTypeFromString(const char str[])
return FSCLOUDLAYER_NONE;
}

FsWeatherCloudLayer FsWeatherCloudLayer::Overcast(double y0,double y1)
{
FsWeatherCloudLayer layer;
layer.cloudLayerType=FSCLOUDLAYER_OVERCAST;
layer.y0=y0;
layer.y1=y1;
return layer;
}




Expand Down Expand Up @@ -162,6 +171,10 @@ void FsWeather::GetCloudLayer(int &nLayer,const FsWeatherCloudLayer *&layer) con
layer=cloudLayer;
}

int FsWeather::GetCloudLayerCount(void) const{
return (int)cloudLayer.GetN();
}

YSBOOL FsWeather::IsInCloudLayer(const YsVec3 &pos) const
{
int i;
Expand Down
2 changes: 2 additions & 0 deletions src/core/fsweather.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class FsWeatherCloudLayer

static const char *CloudLayerTypeString(int cloudLayerType);
static int CloudLayerTypeFromString(const char str[]);
static FsWeatherCloudLayer Overcast(double y0,double y1); // Returns an overclast
};


Expand Down Expand Up @@ -52,6 +53,7 @@ class FsWeather
void SetCloudLayer(YSSIZE_T nLayer,const FsWeatherCloudLayer layer[]);
void AddCloudLayer(const FsWeatherCloudLayer &layer);
void GetCloudLayer(int &nLayer,const FsWeatherCloudLayer *&layer) const;
int GetCloudLayerCount() const;
YSBOOL IsInCloudLayer(const YsVec3 &pos) const;

YSRESULT Save(FILE *fp) const;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/linux/fsnullnetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ YSRESULT FsSocketClient::ReceiveAssignSideWindow(unsigned char dat[])
return YSERR;
}

YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned char dat[])
YSRESULT FsSocketClient::ReceiveVersionNotify(unsigned packetLength,unsigned char dat[])
{
return YSERR;
}
Expand Down