summaryrefslogtreecommitdiff
path: root/src/cgame/cg_ptr.c
blob: 1881087866413531f4cc27249d4cb9eb828a5f63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
===========================================================================
Copyright (C) 2000-2006 Tim Angus

This file is part of Tremulous.

Tremulous 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; either version 2 of the License,
or (at your option) any later version.

Tremulous is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Tremulous; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/

// cg_ptr.c -- post timeout restoration handling


#include "cg_local.h"

#define PTRC_FILE  "ptrc.cfg"

/*
===============
CG_ReadPTRCode

Read a PTR code from disk
===============
*/
int CG_ReadPTRCode( void )
{
  int           len;
  char          text[ 16 ];
  fileHandle_t  f;

  // load the file
  len = trap_FS_FOpenFile( PTRC_FILE, &f, FS_READ );
  if( len <= 0 )
    return 0;

  // should never happen - malformed write
  if( len >= sizeof( text ) - 1 )
    return 0;

  trap_FS_Read( text, len, f );
  text[ len ] = 0;
  trap_FS_FCloseFile( f );

  return atoi( text );
}

/*
===============
CG_WritePTRCode

Write a PTR code to disk
===============
*/
void CG_WritePTRCode( int code )
{
  char          text[ 16 ];
  fileHandle_t  f;

  Com_sprintf( text, 16, "%d", code );

  // open file
  if( trap_FS_FOpenFile( PTRC_FILE, &f, FS_WRITE ) < 0 )
    return;

  // write the code
  trap_FS_Write( text, strlen( text ), f );

  trap_FS_FCloseFile( f );
}