1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 
5 
6 #include "serverobject.h"
7 #include "netconfig.h"
8 #include "serverdata.h"
9 #include "scorevals.h"
10 #include "fileutils.h"
11 
12 
13 void ReadServerConfig(char *ServerConfigFileName);
14 void SetServerDefaults();
15 void ServerAssignValue(char *VariableName, char *value);
16 
17 
18 char ServerConfigFileName[MAX_FILENAME_SIZE];
19 char ServerSingleConfigFileName[MAX_FILENAME_SIZE];
20 int GameSleep;
21 int ServerGameType;
22 int ShotKeepAlive;
23 int ShipDeadTime;
24 int StartLives;
25 int MaxKills;
26 int NumConnectedPlayers;
27 float ServerWorldWidth;
28 int StartAsteroids;
29 int NewAsteroidTime;
30 int AsteroidTimeSpeedup;
31 int MinAsteroidTime;
32 int ServerMaxShield;
33 int StartShield;
34 int ServerMaxArmor;
35 int StartArmor;
36 int MaxPlayers;
37 int PacketSize;
38 int NetSleepTime;
39 int AsteroidScore;
40 int ShipScore;
41 float DecelerationConstant;
42 float AccelerationConstant;
43 float ShipSize;
44 int ShotDamage;
45 int NukeDamage;
46 int NukeShieldDrain;
47 int CollisionDamage;
48 float ShotSpeed;
49 float NukeSpeed;
50 int PowerupAliveTime;
51 int NukeAliveTime;
52 int NukeExplosionAliveTime;
53 float NukeExplosionGrowthSpeed;
54 int ShotAliveTime;
55 float MaxTotalAsteroidSize;
56 int NumBots;
57 float StartBotRatio;
58 float MaxBotRatio;
59 float BotRatioIncrease;
60 int BotFireTime;
61 int BotNukeOdds;
62 int BotShieldTime;
63 int StartWarps;
64 int StartNukes;
65 int PrizeOdds;
66 int ShieldPowerupValue;
67 int ArmorPowerupValue;
68 float RotationSpeed;
69 
70 
ReadServerConfig(char * ServerConfigFileName)71 void ReadServerConfig(char *ServerConfigFileName)
72 {
73   FILE *ConfigFile;
74 
75   SetServerDefaults();
76 
77   if (!(ConfigFile=fopen(ServerConfigFileName, "r"))) {
78     return;
79   }
80 
81   ReadVariables(ConfigFile, &ServerAssignValue);
82 
83   fclose(ConfigFile);
84 }
85 
86 
SetServerDefaults()87 void SetServerDefaults()
88 {
89   ServerWorldWidth=10.0;
90   ServerGameType=1;
91   GamePort=12346;
92   GameSleep=10;
93   ServerMaxShield=300;
94   StartShield=300;
95   ServerMaxArmor=1000;
96   StartArmor=1000;
97   AsteroidScore=1;
98   ShipScore=10;
99   NewAsteroidTime=10000;
100   AsteroidTimeSpeedup=10;
101   MinAsteroidTime=1000;
102   StartAsteroids=3;
103   StartLives=3;
104   MaxKills=20;
105   PacketSize=1024;
106   DecelerationConstant=0.9;
107   AccelerationConstant=0.35;
108   ShipSize=0.2;
109   ShotDamage=50;
110   NukeDamage=350;
111   NukeShieldDrain=50;
112   CollisionDamage=75;
113   ShotSpeed=0.14;
114   NukeSpeed=0.14;
115   PowerupAliveTime=500;
116   ShotAliveTime=50;
117   NukeAliveTime=35;
118   NukeExplosionAliveTime=40;
119   NukeExplosionGrowthSpeed=0.03;
120   MaxTotalAsteroidSize=10.0;
121   NetSleepTime=50;
122   NumBots=0;
123   StartBotRatio=0.25;
124   MaxBotRatio=1.0;
125   BotRatioIncrease=0.002;
126   BotFireTime=20;
127   BotShieldTime=60;
128   BotNukeOdds=5000;
129   StartWarps=2;
130   StartNukes=2;
131   PrizeOdds=512;
132   ShieldPowerupValue=50;
133   ArmorPowerupValue=50;
134   RotationSpeed=1.2;
135 }
136 
137 
ServerAssignValue(char * VariableName,char * value)138 void ServerAssignValue(char *VariableName, char *value)
139 {
140   int temp;
141 
142   if (!strcmp(VariableName, "MAX_NUMBER_OF_PLAYERS")) {
143     MaxPlayers=atoi(value);
144   } else if (!strcmp(VariableName, "GAME_TYPE")) {
145     ServerGameType=atoi(value);
146   } else if (!strcmp(VariableName, "WORLD_WIDTH")) {
147     ServerWorldWidth=strtod(value, NULL);
148   } else if (!strcmp(VariableName, "GAME_PORT")) {
149     GamePort=atoi(value);
150   } else if (!strcmp(VariableName, "SHOT_KEEP_ALIVE")) {
151     ShotKeepAlive=atoi(value);
152   } else if (!strcmp(VariableName, "SHIP_DEAD_TIME")) {
153     ShipDeadTime=atoi(value);
154   } else if (!strcmp(VariableName, "START_LIVES")) {
155     StartLives=atoi(value);
156   } else if (!strcmp(VariableName, "MAX_KILLS")) {
157     MaxKills=atoi(value);
158   } else if (!strcmp(VariableName, "GAME_SLEEP")) {
159     GameSleep=atoi(value);
160   } else if (!strcmp(VariableName, "MAX_SHIELD")) {
161     ServerMaxShield=atoi(value);
162   } else if (!strcmp(VariableName, "START_SHIELD")) {
163     StartShield=atoi(value);
164   } else if (!strcmp(VariableName, "MAX_ARMOR")) {
165     ServerMaxArmor=atoi(value);
166   } else if (!strcmp(VariableName, "START_ARMOR")) {
167     StartArmor=atoi(value);
168   } else if (!strcmp(VariableName, "ASTEROID_SCORE")) {
169     AsteroidScore=atoi(value);
170   } else if (!strcmp(VariableName, "SHIP_SCORE")) {
171     ShipScore=atoi(value);
172   } else if (!strcmp(VariableName, "NEW_ASTEROID_TIME")) {
173     NewAsteroidTime=atoi(value);
174   } else if (!strcmp(VariableName, "ASTEROID_TIME_SPEEDUP")) {
175     AsteroidTimeSpeedup=atoi(value);
176   } else if (!strcmp(VariableName, "MIN_ASTEROID_TIME")) {
177     MinAsteroidTime=atoi(value);
178   } else if (!strcmp(VariableName, "START_ASTEROIDS")) {
179     StartAsteroids=atoi(value);
180   } else if (!strcmp(VariableName, "PACKET_SIZE")) {
181     PacketSize=atoi(value);
182   } else if (!strcmp(VariableName, "NET_SLEEP_TIME")) {
183     NetSleepTime=atoi(value);
184   } else if (!strcmp(VariableName, "DECELERATION_CONSTANT")) {
185     DecelerationConstant=strtod(value, NULL);
186   } else if (!strcmp(VariableName, "ACCELERATION_CONSTANT")) {
187     AccelerationConstant=strtod(value, NULL);
188   } else if (!strcmp(VariableName, "SHIP_SIZE")) {
189     ShipSize=strtod(value, NULL);
190   } else if (!strcmp(VariableName, "SHOT_DAMAGE")) {
191     ShotDamage=atoi(value);
192   } else if (!strcmp(VariableName, "NUKE_DAMAGE")) {
193     NukeDamage=atoi(value);
194   } else if (!strcmp(VariableName, "NUKE_SHIELD_DRAIN")) {
195     NukeShieldDrain=atoi(value);
196   } else if (!strcmp(VariableName, "COLLISION_DAMAGE")) {
197     CollisionDamage=atoi(value);
198   } else if (!strcmp(VariableName, "SHOT_SPEED")) {
199     ShotSpeed=strtod(value, NULL);
200   } else if (!strcmp(VariableName, "NUKE_SPEED")) {
201     NukeSpeed=strtod(value, NULL);
202   } else if (!strcmp(VariableName, "POWERUP_ALIVE_TIME")) {
203     PowerupAliveTime=atoi(value);
204   } else if (!strcmp(VariableName, "NUKE_ALIVE_TIME")) {
205     NukeAliveTime=atoi(value);
206   } else if (!strcmp(VariableName, "NUKE_EXPLOSION_ALIVE_TIME")) {
207     NukeExplosionAliveTime=atoi(value);
208   } else if (!strcmp(VariableName, "NUKE_EXPLOSTION_GROWTH_SPEED")) {
209     NukeSpeed=strtod(value, NULL);
210   } else if (!strcmp(VariableName, "SHOT_ALIVE_TIME")) {
211     ShotAliveTime=atoi(value);
212   } else if (!strcmp(VariableName, "MAX_TOTAL_ASTEROID_SIZE")) {
213     MaxTotalAsteroidSize=strtod(value, NULL);
214   } else if (!strcmp(VariableName, "NUM_BOTS")) {
215     NumBots=atoi(value);
216   } else if (!strcmp(VariableName, "START_BOT_RATIO")) {
217     StartBotRatio=strtod(value, NULL);
218   } else if (!strcmp(VariableName, "MAX_BOT_RATIO")) {
219     MaxBotRatio=strtod(value, NULL);
220   } else if (!strcmp(VariableName, "BOT_RATIO_INCREASE")) {
221     BotRatioIncrease=strtod(value, NULL);
222   } else if (!strcmp(VariableName, "BOT_FIRE_TIME")) {
223     BotFireTime=atoi(value);
224   } else if (!strcmp(VariableName, "BOT_NUKE_ODDS")) {
225     BotNukeOdds=atoi(value);
226   } else if (!strcmp(VariableName, "BOT_SHIELD_TIME")) {
227     BotShieldTime=atoi(value);
228   } else if (!strcmp(VariableName, "START_WARPS")) {
229     StartWarps=atoi(value);
230   } else if (!strcmp(VariableName, "START_NUKES")) {
231     StartNukes=atoi(value);
232   } else if (!strcmp(VariableName, "PRIZE_ODDS")) {
233     PrizeOdds=atoi(value);
234   } else if (!strcmp(VariableName, "SHIELD_POWERUP_VALUE")) {
235     ShieldPowerupValue=atoi(value);
236   } else if (!strcmp(VariableName, "ARMOR_POWERUP_VALUE")) {
237     ArmorPowerupValue=atoi(value);
238   } else if (!strcmp(VariableName, "ROTATION_SPEED")) {
239     RotationSpeed=strtod(value, NULL);
240   }
241 }
242