#define SETUP_FILENAME "setup.conf"
#define LEVELSETUP_FILENAME "levelsetup.conf"
#define LEVELINFO_FILENAME "levelinfo.conf"
+#define LEVELFILE_EXTENSION "level"
#define TAPEFILE_EXTENSION "tape"
#define SCOREFILE_EXTENSION "score"
#else
#define SETUP_FILENAME "setup.cnf"
#define LEVELSETUP_FILENAME "lvlsetup.cnf"
#define LEVELINFO_FILENAME "lvlinfo.cnf"
+#define LEVELFILE_EXTENSION "lvl"
#define TAPEFILE_EXTENSION "rec"
#define SCOREFILE_EXTENSION "sco"
#endif
return score_dir;
}
+static char *getLevelFilename(int nr)
+{
+ static char *filename = NULL;
+ char basename[20 + strlen(LEVELFILE_EXTENSION)];
+
+ if (filename != NULL)
+ free(filename);
+
+ sprintf(basename, "%03d.%s", nr, LEVELFILE_EXTENSION);
+ filename = getPath3((leveldir[leveldir_nr].user_defined ?
+ getUserLevelDir("") :
+ options.level_directory),
+ leveldir[leveldir_nr].filename,
+ basename);
+
+ return filename;
+}
+
+static char *getTapeFilename(int nr)
+{
+ static char *filename = NULL;
+ char basename[20 + strlen(LEVELFILE_EXTENSION)];
+
+ if (filename != NULL)
+ free(filename);
+
+ sprintf(basename, "%03d.%s", nr, TAPEFILE_EXTENSION);
+ filename = getPath2(getTapeDir(leveldir[leveldir_nr].filename), basename);
+
+ return filename;
+}
+
+static char *getScoreFilename(int nr)
+{
+ static char *filename = NULL;
+ char basename[20 + strlen(LEVELFILE_EXTENSION)];
+
+ if (filename != NULL)
+ free(filename);
+
+ sprintf(basename, "%03d.%s", nr, SCOREFILE_EXTENSION);
+ filename = getPath2(getScoreDir(leveldir[leveldir_nr].filename), basename);
+
+ return filename;
+}
+
static void createDirectory(char *dir, char *text)
{
if (access(dir, F_OK) != 0)
void LoadLevel(int level_nr)
{
int i, x, y;
- char filename[MAX_FILENAME_LEN];
+ char *filename = getLevelFilename(level_nr);
char cookie[MAX_LINE_LEN];
char chunk[CHUNK_ID_LEN + 1];
int file_version = FILE_VERSION_1_2; /* last version of level files */
/* always start with reliable default values */
setLevelInfoToDefaults();
- if (leveldir[leveldir_nr].user_defined)
- sprintf(filename, "%s/%s/%d",
- getUserLevelDir(""), leveldir[leveldir_nr].filename, level_nr);
- else
- sprintf(filename, "%s/%s/%d",
- options.level_directory, leveldir[leveldir_nr].filename, level_nr);
-
if (!(file = fopen(filename, "r")))
{
Error(ERR_WARN, "cannot read level '%s' - creating new level", filename);
void SaveLevel(int level_nr)
{
int i, x, y;
- char filename[MAX_FILENAME_LEN];
+ char *filename = getLevelFilename(level_nr);
FILE *file;
int chunk_length;
- if (leveldir[leveldir_nr].user_defined)
- sprintf(filename, "%s/%s/%d",
- getUserLevelDir(""), leveldir[leveldir_nr].filename, level_nr);
- else
- sprintf(filename, "%s/%s/%d",
- options.level_directory, leveldir[leveldir_nr].filename, level_nr);
-
if (!(file = fopen(filename, "w")))
{
Error(ERR_WARN, "cannot save level file '%s'", filename);
void LoadTape(int level_nr)
{
int i, j;
- char filename[MAX_FILENAME_LEN];
+ char *filename = getTapeFilename(level_nr);
char cookie[MAX_LINE_LEN];
char chunk[CHUNK_ID_LEN + 1];
FILE *file;
int file_version = FILE_VERSION_1_2; /* last version of tape files */
int chunk_length;
- sprintf(filename, "%s/%d.%s",
- getTapeDir(leveldir[leveldir_nr].filename),
- level_nr, TAPEFILE_EXTENSION);
-
if (!(file = fopen(filename, "r")))
return;
void SaveTape(int level_nr)
{
int i;
- char filename[MAX_FILENAME_LEN];
+ char *filename = getTapeFilename(level_nr);
FILE *file;
boolean new_tape = TRUE;
byte store_participating_players;
InitTapeDirectory(leveldir[leveldir_nr].filename);
- sprintf(filename, "%s/%d.%s",
- getTapeDir(leveldir[leveldir_nr].filename),
- level_nr, TAPEFILE_EXTENSION);
-
/* if a tape still exists, ask to overwrite it */
if ((file = fopen(filename, "r")))
{
void LoadScore(int level_nr)
{
int i;
- char filename[MAX_FILENAME_LEN];
+ char *filename = getScoreFilename(level_nr);
char cookie[MAX_LINE_LEN];
char line[MAX_LINE_LEN];
char *line_ptr;
FILE *file;
- /* start with empty score table */
+ /* always start with reliable default values */
for(i=0; i<MAX_SCORE_ENTRIES; i++)
{
strcpy(highscore[i].Name, EMPTY_ALIAS);
highscore[i].Score = 0;
}
- sprintf(filename, "%s/%d.%s",
- getScoreDir(leveldir[leveldir_nr].filename),
- level_nr, SCOREFILE_EXTENSION);
-
if (!(file = fopen(filename, "r")))
return;
/* check file identifier */
fgets(cookie, MAX_LINE_LEN, file);
+ if (strlen(cookie) > 0 && cookie[strlen(cookie) - 1] == '\n')
+ cookie[strlen(cookie) - 1] = '\0';
if (strcmp(cookie, SCORE_COOKIE) != 0)
{
void SaveScore(int level_nr)
{
int i;
- char filename[MAX_FILENAME_LEN];
+ char *filename = getScoreFilename(level_nr);
FILE *file;
InitScoreDirectory(leveldir[leveldir_nr].filename);
- sprintf(filename, "%s/%d.%s",
- getScoreDir(leveldir[leveldir_nr].filename),
- level_nr, SCOREFILE_EXTENSION);
-
if (!(file = fopen(filename, "w")))
{
Error(ERR_WARN, "cannot save score for level %d", level_nr);
-/*
- * A server for a multi-player version of Tetris
- *
- * Copyright (C) 1996 Roger Espel Llima <roger.espel.llima@pobox.com>
- *
- * Started: 10 Oct 1996
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation. See the file COPYING for details.
- *
- */
+/***********************************************************
+* Rocks'n'Diamonds -- McDuffin Strikes Back! *
+*----------------------------------------------------------*
+* (c) 1995-98 Artsoft Entertainment *
+* Holger Schemel *
+* Oststrasse 11a *
+* 33604 Bielefeld *
+* phone: ++49 +521 290471 *
+* email: aeglos@valinor.owl.de *
+*----------------------------------------------------------*
+* network.c *
+***********************************************************/
#include <stdio.h>
#include <stdlib.h>
static void Handle_OP_PROTOCOL_VERSION(struct user *u, unsigned int len)
{
- if (len != 5 || buf[2] != PROT_VERS_1 || buf[3] != PROT_VERS_2)
+ if (len != 5 || buf[2] != PROTOCOL_VERSION_1 || buf[3] != PROTOCOL_VERSION_2)
{
if (options.verbose)
printf("RND_SERVER: client %d (%s) has wrong protocol version %d.%d.%d\n", u->number, u->nick, buf[2], buf[3], buf[4]);
buf[0] = 0;
buf[1] = OP_BADVERS;
- buf[2] = PROT_VERS_1;
- buf[3] = PROT_VERS_2;
- buf[4] = PROT_VERS_3;
+ buf[2] = PROTOCOL_VERSION_1;
+ buf[3] = PROTOCOL_VERSION_2;
+ buf[4] = PROTOCOL_VERSION_3;
sendtoone(u, 5);
flushuser(u);
printf("rocksndiamonds network server: started up, listening on port %d\n",
port);
printf("rocksndiamonds network server: using protocol version %d.%d.%d\n",
- PROT_VERS_1, PROT_VERS_2, PROT_VERS_3);
+ PROTOCOL_VERSION_1, PROTOCOL_VERSION_2, PROTOCOL_VERSION_3);
}
while(1)