diff --git a/src/core/fsnetwork.cpp b/src/core/fsnetwork.cpp index e1a36b1a..14d9b7f5 100644 --- a/src/core/fsnetwork.cpp +++ b/src/core/fsnetwork.cpp @@ -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. } @@ -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; } @@ -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); } @@ -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; @@ -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) @@ -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); } @@ -4955,6 +4980,7 @@ FsSocketClient::FsSocketClient(const char username[],const int port,FsSimulation sideWindowAssigned=YSFALSE; reportedServerVersion=0; + ysceServer=YSFALSE; svrUseMissile=YSTRUE; svrUseUnguidedWeapon=YSTRUE; @@ -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); @@ -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) @@ -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); diff --git a/src/core/fsnetwork.h b/src/core/fsnetwork.h index aad01dac..cd27f211 100644 --- a/src/core/fsnetwork.h +++ b/src/core/fsnetwork.h @@ -187,6 +187,7 @@ class FsNetworkUser YsArray gndToSend,airToSend; YSBOOL useMissileReadBack,useUnguidedWeaponReadBack,controlShowUserNameReadBack; YSBOOL environmentReadBack,preparationReadBack; + YSBOOL usingYSCE; YsArray gndRmvToSend,airRmvToSend; int joinSequence; // 0:Not in process 1:Waiting for Airplane Read Back 2:Waiting for SetPlayer Read Back @@ -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); @@ -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[]); diff --git a/src/core/fsweather.cpp b/src/core/fsweather.cpp index f89c9af2..3b87a47a 100644 --- a/src/core/fsweather.cpp +++ b/src/core/fsweather.cpp @@ -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; +} + @@ -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; diff --git a/src/core/fsweather.h b/src/core/fsweather.h index 3308354b..1bb6508e 100644 --- a/src/core/fsweather.h +++ b/src/core/fsweather.h @@ -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 }; @@ -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; diff --git a/src/platform/linux/fsnullnetwork.cpp b/src/platform/linux/fsnullnetwork.cpp index fa8053bf..3e95c5ec 100644 --- a/src/platform/linux/fsnullnetwork.cpp +++ b/src/platform/linux/fsnullnetwork.cpp @@ -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; }