4b825dc642cb6eb9a060e54bf8d69288fbee490494a6641b73026d662261604d7d192beae70b11dc
 
 
1
#include "files.h"
 
 
2
#include "net.h"
 
 
3
#include <string.h>
 
 
4
#include <stdlib.h>
 
 
5
 
 
 
6
#define MP_CONFIG_DIR "mp_config/"
 
 
7
#define MP_CONFIG_WILDCARD "*.cfg"
 
 
8
#define SKIRMISH_CONFIG_WILDCARD "*.skirmish_cfg"
 
 
9
#define IP_ADDRESS_DIR "ip_address/"
 
 
10
#define IP_ADDRESS_WILDCARD "*.IP Address"
 
 
11
 
 
 
12
extern char MP_SessionName[];
 
 
13
extern char MP_Config_Description[];
 
 
14
extern int CloseGameDirectory(void *dir);
 
 
15
extern int CreateGameDirectory(const char *dirname);
 
 
16
 
 
 
17
extern const char * coop_levels[];
 
 
18
extern const char * multiplayer_levels[];
 
 
19
 
 
 
20
static int custom_multiplayer_levels = 0;
 
 
21
static int custom_coop_skirmish_levels = 0;
 
 
22
int NumMultiplayerLevels = 0;
 
 
23
int NumCoopLevels = MAX_NO_OF_COOPERATIVE_EPISODES;
 
 
24
const char** MultiplayerLevelNames = NULL;
 
 
25
const char** CoopLevelNames = NULL;
 
 
26
char *LastDescriptionFile = NULL;
 
 
27
char* LastDescriptionText = NULL;
 
 
28
 
 
 
29
//returns local index of a custom level (if it is a custom level)
 
 
30
static int GetCustomMultiplayerLevelIndex(char* name, int coop)
 
 
31
{
 
 
32
    char buffer[256];
 
 
33
    sprintf(buffer,"%s (%s)", name, "custom");
 
 
34
 
 
 
35
    //find the index of a custom level from its name
 
 
36
    if(coop)
 
 
37
    {
 
 
38
        int i = MAX_NO_OF_COOPERATIVE_EPISODES;
 
 
39
 
 
 
40
        for(; i < NumCoopLevels ;i++)
 
 
41
        {
 
 
42
            if(!strcasecmp(buffer, CoopLevelNames[i]))
 
 
43
                return i;
 
 
44
        }
 
 
45
    }
 
 
46
    else
 
 
47
    {
 
 
48
        int i = MAX_NO_OF_MULTIPLAYER_EPISODES;
 
 
49
 
 
 
50
        for(; i < NumMultiplayerLevels;i++)
 
 
51
        {
 
 
52
            if(!strcasecmp(buffer, MultiplayerLevelNames[i]))
 
 
53
                return i;
 
 
54
        }
 
 
55
    }
 
 
56
 
 
 
57
return -1;
 
 
58
}
 
 
59
 
 
 
60
void SetDefaultNetStruct()
 
 
61
{
 
 
62
    int i;
 
 
63
    netGameData.myCharacterSubType = NGSCT_General;
 
 
64
    netGameData.myCharacterType = NGCT_Marine;
 
 
65
    netGameData.myNextCharacterType= NGCT_Marine;
 
 
66
    netGameData.gameType = NGT_Coop;
 
 
67
    netGameData.myGameState = NGS_StartUp;
 
 
68
    netGameData.LMS_AlienIndex = -1;
 
 
69
    netGameData.LMS_RestartTimer = 0;
 
 
70
    netGameData.myLastScream = -1;
 
 
71
    netGameData.GameTimeElapsed = 0;
 
 
72
    netGameData.myStartFlag = 0;
 
 
73
    netGameData.levelNumber = 0;
 
 
74
    netGameData.sendDecals = 1;
 
 
75
    netGameData.sendTimer = 0;
 
 
76
    netGameData.sendFrequency = 0;
 
 
77
    netGameData.pointsForRespawn = 0;
 
 
78
    netGameData.lastPointsBasedRespawn = 0;
 
 
79
    netGameData.gameDescriptionTimeDelay = 0;
 
 
80
    netGameData.needGameDescription = 0;
 
 
81
    netGameData.stateCheckTimeDelay = 0;
 
 
82
    netGameData.myStrategyCheckSum = 0;
 
 
83
    netGameData.customLevelName[0] = '\0';
 
 
84
    netGameData.joiningGameStatus = 0;
 
 
85
    netGameData.teamScores[0] = 0;
 
 
86
    netGameData.teamScores[1] = 0;
 
 
87
    netGameData.teamScores[2] = 0;
 
 
88
    netGameData.numDeaths[0] = 0;
 
 
89
    netGameData.numDeaths[1] = 0;
 
 
90
    netGameData.numDeaths[2] = 0;
 
 
91
    netGameData.landingNoise = 0;
 
 
92
 
 
 
93
    for(i=0; i < NET_MAXPLAYERS; i++)
 
 
94
    {
 
 
95
        int j;
 
 
96
        netGameData.playerData[i].playerId = 0;        
 
 
97
 
 
 
98
        for(j=0; j < NET_PLAYERNAMELENGTH; j++)
 
 
99
            netGameData.playerData[i].name[j] = '\0';
 
 
100
 
 
 
101
        netGameData.playerData[i].characterType = NGCT_Marine;
 
 
102
        netGameData.playerData[i].characterSubType = NGSCT_General;
 
 
103
 
 
 
104
        for(j=0; j < NET_MAXPLAYERS; j++)
 
 
105
            netGameData.playerData[i].playerFrags[j] = 0;
 
 
106
 
 
 
107
        netGameData.playerData[i].aliensKilled[0] = 0;
 
 
108
        netGameData.playerData[i].aliensKilled[1] = 0;
 
 
109
        netGameData.playerData[i].aliensKilled[2] = 0;
 
 
110
        netGameData.playerData[i].deathsFromAI = 0;
 
 
111
        netGameData.playerData[i].playerScore = 0;
 
 
112
        netGameData.playerData[i].playerScoreAgainst = 0;
 
 
113
        netGameData.playerData[i].lastKnownPosition.vx = 0;
 
 
114
        netGameData.playerData[i].lastKnownPosition.vy = 0;
 
 
115
        netGameData.playerData[i].lastKnownPosition.vz = 0;
 
 
116
        netGameData.playerData[i].timer = 0;
 
 
117
        netGameData.playerData[i].startFlag = 0;
 
 
118
        netGameData.playerData[i].playerAlive = 1;
 
 
119
        netGameData.playerData[i].playerHasLives = 1;
 
 
120
    }
 
 
121
}
 
 
122
 
 
 
123
void SetDefaultMultiplayerConfig()
 
 
124
{
 
 
125
    netGameData.timeForRespawn = 40;
 
 
126
    netGameData.invulnerableTime = 5;
 
 
127
    netGameData.useSharedLives = 0;
 
 
128
    netGameData.maxLives = 0;
 
 
129
    netGameData.scoreLimit = 1000000;    
 
 
130
    netGameData.timeLimit = 255;
 
 
131
    netGameData.invulnerableTime = 5;
 
 
132
    netGameData.characterKillValues[0] = 100;
 
 
133
    netGameData.characterKillValues[1] = 150;
 
 
134
    netGameData.characterKillValues[2] = 75;
 
 
135
 
 
 
136
    netGameData.baseKillValue = 100;
 
 
137
    netGameData.useDynamicScoring = 1;
 
 
138
    netGameData.useCharacterKillValues = 1;
 
 
139
 
 
 
140
    netGameData.aiKillValues[0] = 75;
 
 
141
    netGameData.aiKillValues[1] = 100;
 
 
142
    netGameData.aiKillValues[2] = 150;
 
 
143
 
 
 
144
    netGameData.maxPredator = 8;
 
 
145
    netGameData.maxAlien = 8;
 
 
146
    netGameData.maxMarine = 8;
 
 
147
    netGameData.maxMarineGeneral = 8;
 
 
148
    netGameData.maxMarinePulseRifle = 8;
 
 
149
    netGameData.maxMarineSmartgun = 8;
 
 
150
    netGameData.maxMarineFlamer = 8;
 
 
151
    netGameData.maxMarineSadar = 8;
 
 
152
    netGameData.maxMarineGrenade = 8;
 
 
153
    netGameData.maxMarineMinigun = 8;
 
 
154
    netGameData.maxMarineSmartDisc = 8;
 
 
155
    netGameData.maxMarinePistols = 8;
 
 
156
 
 
 
157
    netGameData.allowSmartgun = 1;
 
 
158
    netGameData.allowFlamer = 1;
 
 
159
    netGameData.allowSadar = 1;
 
 
160
    netGameData.allowGrenadeLauncher = 1;
 
 
161
    netGameData.allowMinigun = 1;
 
 
162
    netGameData.allowDisc = 1;
 
 
163
    netGameData.allowPistol = 1;
 
 
164
    netGameData.allowPlasmaCaster = 1;
 
 
165
    netGameData.allowSpeargun = 1;
 
 
166
    netGameData.allowMedicomp = 1;
 
 
167
    netGameData.allowSmartDisc = 1;
 
 
168
    netGameData.allowPistols = 1;
 
 
169
    netGameData.preDestroyLights = 0;
 
 
170
    netGameData.disableFriendlyFire = 0;
 
 
171
    netGameData.fallingDamage = 1;
 
 
172
    netGameData.pistolInfiniteAmmo = 1;
 
 
173
    netGameData.specialistPistols = 1;
 
 
174
 
 
 
175
    netGameData.maxLives = 0;
 
 
176
    netGameData.useSharedLives = 0;
 
 
177
    netGameData.pointsForRespawn = 0;
 
 
178
    netGameData.timeForRespawn = 40;
 
 
179
    netGameData.gameSpeed = NETGAMESPEED_100PERCENT;
 
 
180
}
 
 
181
 
 
 
182
void LoadMultiplayerConfiguration(const char* name)
 
 
183
{
 
 
184
    char filename[200];
 
 
185
    SetDefaultMultiplayerConfig(); //set defaults first , in case there are entries not set by this file
 
 
186
 
 
 
187
    sprintf(filename,"%s%c%s.%scfg", MP_CONFIG_DIR, DIR_SEPARATOR, name, ((Skirmish == AvP.PlayMode) ? "skirmish_" : "" ));
 
 
188
 
 
 
189
    FILE* file = OpenGameFile(filename, 1, FILETYPE_CONFIG);
 
 
190
 
 
 
191
    if(NULL != file)
 
 
192
    {
 
 
193
        fread(&netGameData, sizeof(netGameData), 1, file);
 
 
194
        fread(&MP_SessionName[0], sizeof(char), 13, file);
 
 
195
 
 
 
196
        int description_length = 0;
 
 
197
        fread(&description_length, sizeof(int), 1, file);
 
 
198
        fread(MP_Config_Description, 1, description_length, file);
 
 
199
 
 
 
200
        //read the custom level name
 
 
201
        int length = 0;
 
 
202
        fread(&length, sizeof(int), 1, file);
 
 
203
 
 
 
204
        if(length)
 
 
205
        {
 
 
206
            fread(netGameData.customLevelName, 1, length, file);
 
 
207
            //if the custom level name has been set , we need to find the index
 
 
208
 
 
 
209
            if(0)
 
 
210
            if(netGameData.customLevelName[0])
 
 
211
            {
 
 
212
                netGameData.levelNumber = GetCustomMultiplayerLevelIndex(netGameData.customLevelName, (NGT_Coop == netGameData.gameType));
 
 
213
 
 
 
214
                if(netGameData.levelNumber < 0)
 
 
215
                {
 
 
216
                    //we don't have the level
 
 
217
                    netGameData.levelNumber = 0;
 
 
218
                    netGameData.customLevelName[0] = 0;
 
 
219
                }
 
 
220
            }
 
 
221
        }
 
 
222
 
 
 
223
        fclose(file);
 
 
224
    }
 
 
225
}
 
 
226
 
 
 
227
void SaveMultiplayerConfiguration(const char* name)
 
 
228
{
 
 
229
    char filename[200];
 
 
230
 
 
 
231
    sprintf(filename,"%s%c%s.%scfg", MP_CONFIG_DIR, DIR_SEPARATOR, name, ((Skirmish == AvP.PlayMode) ? "skirmish_" : "" ));
 
 
232
 
 
 
233
    FILE* file = OpenGameFile(filename, 0, FILETYPE_CONFIG);
 
 
234
 
 
 
235
    if (file == NULL)
 
 
236
    {
 
 
237
        CreateGameDirectory(MP_CONFIG_DIR); /* try again */
 
 
238
 
 
 
239
        file = OpenGameFile(filename, 0, FILETYPE_CONFIG);
 
 
240
 
 
 
241
        if (file == NULL)
 
 
242
            return;
 
 
243
    }
 
 
244
 
 
 
245
    fwrite(&netGameData, sizeof(netGameData), 1, file);
 
 
246
    fwrite(&MP_SessionName[0], sizeof(char), 13, file);
 
 
247
 
 
 
248
    //write the description of the config
 
 
249
    int length = strlen(MP_Config_Description)+1;
 
 
250
    fwrite(&length, sizeof(int), 1, file);
 
 
251
    fwrite(MP_Config_Description, 1, length, file);
 
 
252
 
 
 
253
    //write the custom level name (if relevant)
 
 
254
    length = strlen(netGameData.customLevelName)+1;
 
 
255
    fwrite(&length, sizeof(int), 1, file);
 
 
256
    fwrite(netGameData.customLevelName, 1, length, file);
 
 
257
 
 
 
258
    fclose(file);
 
 
259
 
 
 
260
    //clear the last description stuff
 
 
261
    free(LastDescriptionFile);
 
 
262
    LastDescriptionFile = NULL;
 
 
263
    free(LastDescriptionText);
 
 
264
    LastDescriptionText = NULL;
 
 
265
}
 
 
266
 
 
 
267
void SaveIPAddress(const char* name, const char* address)
 
 
268
{
 
 
269
    if(!name || !address || !strlen(name) || !strlen(address))
 
 
270
        return;
 
 
271
 
 
 
272
    char filename[200];
 
 
273
    sprintf(filename,"%s/%s.IP Address",IP_ADDRESS_DIR,name);
 
 
274
 
 
 
275
    FILE* file = OpenGameFile(filename, 0, FILETYPE_CONFIG);
 
 
276
 
 
 
277
    if (file == NULL)
 
 
278
    {
 
 
279
        CreateGameDirectory(IP_ADDRESS_DIR); /* try again */
 
 
280
 
 
 
281
        file = OpenGameFile(filename, 0, FILETYPE_CONFIG);
 
 
282
 
 
 
283
        if (file == NULL)
 
 
284
             return;
 
 
285
    }
 
 
286
 
 
 
287
    fwrite(address,1,strlen(address)+1,file);
 
 
288
 
 
 
289
    fclose(file);
 
 
290
}
 
 
291
 
 
 
292
void LoadIPAddress(const char* name)
 
 
293
{
 
 
294
    extern char IPAddressString[]; 
 
 
295
 
 
 
296
    if(!name)
 
 
297
        return;
 
 
298
 
 
 
299
    FILE* file;
 
 
300
    char filename[200];
 
 
301
    sprintf(filename,"%s/%s.IP Address",IP_ADDRESS_DIR,name);
 
 
302
 
 
 
303
    file = OpenGameFile(filename, 1, FILETYPE_CONFIG);
 
 
304
 
 
 
305
    if(!file)
 
 
306
        return;
 
 
307
 
 
 
308
    fread(IPAddressString,1,16,file);
 
 
309
    IPAddressString[15]=0;
 
 
310
 
 
 
311
    fclose(file);
 
 
312
}
 
 
313
 
 
 
314
void cleanup_strings()
 
 
315
{
 
 
316
    int i;
 
 
317
 
 
 
318
    for(i=0; i < custom_coop_skirmish_levels; i++)
 
 
319
        free((void*)CoopLevelNames[MAX_NO_OF_COOPERATIVE_EPISODES + i]);
 
 
320
 
 
 
321
    for(i=0; i < custom_multiplayer_levels; i++)
 
 
322
        free((void*)MultiplayerLevelNames[MAX_NO_OF_MULTIPLAYER_EPISODES + i]);
 
 
323
 
 
 
324
    free(MultiplayerLevelNames);
 
 
325
    free(CoopLevelNames);
 
 
326
}
 
 
327
 
 
 
328
extern void *OpenGameDirectory(const char *dirname, const char *pattern, int type);
 
 
329
extern GameDirectoryFile *ScanGameDirectory(void *dir);
 
 
330
 
 
 
331
void BuildMultiplayerLevelNameArray()
 
 
332
{
 
 
333
    //first do a search for custom level rifs
 
 
334
    // allow a wildcard search
 
 
335
    void *gd;
 
 
336
 
 
 
337
    char ** CustomCoopSkirmishLevelNameList = malloc(sizeof(char*)* 14); // 14 = all avp gold map packs installed
 
 
338
    char ** CustomMultiPlayerLevelNameList = malloc(sizeof(char*)* 14); // 14 = all avp gold map packs installed
 
 
339
 
 
 
340
    /* TODO: Have to use PERM until the load_rif code can handle CONFIG */
 
 
341
    if ((gd = OpenGameDirectory("avp_rifs/custom/", "*.rif", FILETYPE_GAMEDATA)) != NULL)
 
 
342
    {
 
 
343
        GameDirectoryFile *gdf;
 
 
344
 
 
 
345
        while ((gdf = ScanGameDirectory(gd)) != NULL)
 
 
346
        {
 
 
347
            if ((gdf->attr & FILEATTR_DIRECTORY) || !(gdf->attr & FILEATTR_READABLE))
 
 
348
                continue;
 
 
349
 
 
 
350
            char * level_rif = strstr(gdf->filename, ".rif");
 
 
351
 
 
 
352
            if(NULL != level_rif)
 
 
353
            {
 
 
354
                int custom_filename_len = strlen(gdf->filename);
 
 
355
 
 
 
356
                if(NULL != strstr(gdf->filename, "(c)"))
 
 
357
                {
 
 
358
                    char *custom_map = malloc(custom_filename_len + 1);
 
 
359
                    strncpy(custom_map, gdf->filename, custom_filename_len + 1);
 
 
360
 
 
 
361
                    if(custom_coop_skirmish_levels > 13)
 
 
362
                        CustomCoopSkirmishLevelNameList = (char**)realloc(CustomCoopSkirmishLevelNameList,(sizeof(char**) * (14 + custom_coop_skirmish_levels +
1)));
 
 
363
 
 
 
364
                    CustomCoopSkirmishLevelNameList[custom_coop_skirmish_levels++] = custom_map;
 
 
365
                }
 
 
366
                else
 
 
367
                {
 
 
368
                    char *custom_map = malloc(custom_filename_len + 1);
 
 
369
                    strncpy(custom_map, gdf->filename, custom_filename_len + 1);
 
 
370
 
 
 
371
                    if(custom_multiplayer_levels > 13)
 
 
372
                        CustomMultiPlayerLevelNameList = (char**)realloc(CustomMultiPlayerLevelNameList, (sizeof(char**) * (14 + custom_multiplayer_levels +
1)));
 
 
373
 
 
 
374
                    CustomMultiPlayerLevelNameList[custom_multiplayer_levels++] = custom_map;
 
 
375
                }
 
 
376
            }
 
 
377
        }
 
 
378
 
 
 
379
        CloseGameDirectory(gd);
 
 
380
    }
 
 
381
    else
 
 
382
    {
 
 
383
        CreateGameDirectory("custom"); // maybe it didn't exist..
 
 
384
    }
 
 
385
 
 
 
386
    NumMultiplayerLevels = MAX_NO_OF_MULTIPLAYER_EPISODES + custom_multiplayer_levels;
 
 
387
    NumCoopLevels += custom_coop_skirmish_levels;
 
 
388
 
 
 
389
    MultiplayerLevelNames = malloc(sizeof(char*)* NumMultiplayerLevels);
 
 
390
 
 
 
391
    int i=0;
 
 
392
    //first the standard multiplayer levels
 
 
393
    for(i=0; i < MAX_NO_OF_MULTIPLAYER_EPISODES; i++)
 
 
394
        MultiplayerLevelNames[i] = multiplayer_levels[i];
 
 
395
 
 
 
396
    CoopLevelNames = malloc(sizeof(char*)* NumCoopLevels);
 
 
397
 
 
 
398
    //and the standard coop levels
 
 
399
    for(i=0; i < MAX_NO_OF_COOPERATIVE_EPISODES; i++)
 
 
400
        CoopLevelNames[i] = coop_levels[i];
 
 
401
 
 
 
402
    for(i=0; i < custom_coop_skirmish_levels; i++)
 
 
403
        CoopLevelNames[MAX_NO_OF_COOPERATIVE_EPISODES + i] = CustomCoopSkirmishLevelNameList[i];
 
 
404
 
 
 
405
    for(i=0; i < custom_multiplayer_levels; i++)
 
 
406
        MultiplayerLevelNames[MAX_NO_OF_MULTIPLAYER_EPISODES + i] = CustomMultiPlayerLevelNameList[i];
 
 
407
 
 
 
408
    free(CustomCoopSkirmishLevelNameList);
 
 
409
    free(CustomMultiPlayerLevelNameList);
 
 
410
}