From de4e02eefcc83fa250ef437b2d175b5907d19ab6 Mon Sep 17 00:00:00 2001 From: Skipper Date: Fri, 21 Jul 2023 21:21:37 +0100 Subject: [PATCH 1/2] Added check to allow 2015+ connections --- src/core/fsnetwork.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/fsnetwork.cpp b/src/core/fsnetwork.cpp index fdc3088f..b42d2bfc 100644 --- a/src/core/fsnetwork.cpp +++ b/src/core/fsnetwork.cpp @@ -2536,7 +2536,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; } From b4e183fe55c3ac0d5ee7d5b9aa444c84eea0fae3 Mon Sep 17 00:00:00 2001 From: Skipper Date: Sun, 30 Jul 2023 22:19:07 +0100 Subject: [PATCH 2/2] Some work on clouds and environment net code --- src/core/fsnetwork.cpp | 54 +++++++++++++++++++++++----- src/core/fsnetwork.h | 4 ++- src/core/fsweather.cpp | 13 +++++++ src/core/fsweather.h | 2 ++ src/platform/linux/fsnullnetwork.cpp | 2 +- 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/core/fsnetwork.cpp b/src/core/fsnetwork.cpp index b42d2bfc..34b9f0e7 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. } @@ -3756,8 +3758,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); } @@ -4189,6 +4195,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; @@ -4260,10 +4267,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) @@ -4330,13 +4345,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); } @@ -4941,6 +4966,7 @@ FsSocketClient::FsSocketClient(const char username[],const int port,FsSimulation sideWindowAssigned=YSFALSE; reportedServerVersion=0; + ysceServer=YSFALSE; svrUseMissile=YSTRUE; svrUseUnguidedWeapon=YSTRUE; @@ -5076,7 +5102,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); @@ -5704,9 +5730,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) @@ -6403,13 +6430,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 cecb27c5..dfb494f1 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 @@ -533,6 +534,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); @@ -608,7 +610,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; }