-
Notifications
You must be signed in to change notification settings - Fork 1
/
inc_charactersave.php
216 lines (200 loc) · 8.85 KB
/
inc_charactersave.php
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
/*
Kremica was coded entirely by Ryan Johnston, a senior at the University
of Pittsburgh. Kremica is meant to be an enjoyable (yet frustrating)
game that will not over-burden a student. Rather, the game functions as
something to do on a quick study break. Make a character, play until the
character dies, go back to studying.
Copyright (C) 2010 Ryan Johnston
For a copy of the GNU GPL, visit:
http://www.gnu.org/licenses/gpl.html
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, either version 3 of the License, or
(at your option) any later version.
This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*/
if (isset($_SESSION["name"])) {
$name = $_SESSION['name'];
include 'inc_connection.php';
//If there is already a character in the database by this name, just update it.
//If there isn't, insert
//Else, return error.
//First, run a select to see if there are any results for the charactername
$searchquery="SELECT name FROM characters WHERE name='" . trim(mysql_real_escape_string($_SESSION['name'])) . "'";
//If there are no results, insert.
if (mysql_num_rows(mysql_query($searchquery))==0) {
$runthisquery="INSERT INTO characters VALUES (NULL, '$name', '" . $_SESSION['hp'] . "', '" . $_SESSION['maxhp'] . "', '" . $_SESSION['level'] . "', '" . $_SESSION['strength'] . "', '" . $_SESSION['defense'] . "', '" . $_SESSION['speed'] . "', '" . $_SESSION['agility'] . "', '" . $_SESSION['accuracy'] . "', '" . $_SESSION['weaponholster'][0][4] . "',";
//(characterid, name, hp, maxhp, level, strength, defense, weapon1, weapon2, weapon3, shield1, shield2, shield3, username, dead, exp, maxexp)
//The following if statements are here because the character may or may not
//have a weapon/shield in slots 1 and 2. He/she will ALWAYS have a weapon
//in slot 0.
if (isset($_SESSION['weaponholster'][1][4])) {
$runthisquery.=" '" . $_SESSION['weaponholster'][1][4] . "',";
}
else {
$runthisquery.=" NULL,";
}
if (isset($_SESSION['weaponholster'][2][4])) {
$runthisquery.=" '" . $_SESSION['weaponholster'][2][4] . "',";
}
else {
$runthisquery.=" NULL,";
}
//First Shield
$runthisquery.=" '" . $_SESSION['shieldholster'][0][3] . "',";
//Then the second and third slots
if (isset($_SESSION['shieldholster'][1][3])) {
$runthisquery.=" '" . $_SESSION['shieldholster'][1][3] . "',";
}
else {
$runthisquery.=" NULL,";
}
if (isset($_SESSION['shieldholster'][2][3])) {
$runthisquery.=" '" . $_SESSION['shieldholster'][2][3] . "',";
}
else {
$runthisquery.=" NULL,";
}
$runthisquery.=" 'no', '". $_SESSION['exp'] . "', '" . $_SESSION['maxexp'] . "',";
//Must do this for Potions and Items, too
//If there are potions in the potion holster, record them. If not, insert NULL.
//Ends with a comma (,)
$x=0;
while (isset($_SESSION['potionholster'][$x][2])) {
$runthisquery.=" '" . $_SESSION['potionholster'][$x][2] . "',";
$x++;
}
//There may not be 5 potions. If this is the case, x will not reach 4.
//If there are no potions anymore, send a null until x is 4.
while ($x<=4) {
$runthisquery.=" NULL,";
$x++;
}
//If there are items in the item holster, record them. if not, insert NULL.
//Ends with a comma(,)
$x=0;
while (isset($_SESSION['itemholster'][$x][2])) {
$runthisquery.=" '" . $_SESSION['itemholster'][$x][2] . "',";
$x++;
}
//There might not be 5 items. If this is the case, x will not reach 4.
//If there are no more items, send a null until x is 4.
while ($x<=4) {
$runthisquery.=" NULL,";
$x++;
}
$runthisquery.=" '" . $_SESSION['weaponequippedID'] . "', '" . $_SESSION['shieldequippedID'] . "', '" . $_SESSION['gold'] . "', '" . $_SESSION['userID'] . "',";
//Quest Stuff
$runthisquery.=" '" . $_SESSION['questID'] . "', '" . $_SESSION['queststep'] . "', ";
//Gender Stuff
$runthisquery.=" '" . $_SESSION['gender'] . "', ";
//Fist/barearms type (just in case)
$runthisquery.=" '" . $_SESSION['weaponholster'][0][3] . "', '" . $_SESSION['shieldholster'][0][2] . "'";
$runthisquery.=")";
//echo $runthisquery;
}
//If there is exactly 1 result, update
else if (mysql_num_rows(mysql_query($searchquery))==1){
$runthisquery="UPDATE characters SET hp='" . $_SESSION['hp'] . "', maxhp='" . $_SESSION['maxhp'] . "', level='" . $_SESSION['level'] . "', strength='" . $_SESSION['strength'] . "', defense='" . $_SESSION['defense'] . "', speed='" . $_SESSION['speed'] . "', agility='" . $_SESSION['agility'] . "', accuracy='" . $_SESSION['accuracy'] . "', weapon1='" . $_SESSION['weaponholster'][0][4] . "',";
//(characterid, name, hp, maxhp, level, strength, defense, weapon1, weapon2, weapon3, shield1, shield2, shield3, username, dead, exp, maxexp, numberofpotionholsterslots, numberofitemsinpotionholster, potion1, potion2, potion3, potion4, potion5, item1, item2, item3, item4, item5, weaponequipped, shieldequipped, gold)
//The following if statements are here because the character may or may not
//have a weapon/shield in slots 1 and 2. He/she will ALWAYS have a weapon
//in slot 0.
if (isset($_SESSION['weaponholster'][1][4])) {
$runthisquery.=" weapon2='" . $_SESSION['weaponholster'][1][4] . "',";
}
else {
$runthisquery.=" weapon2=NULL,";
}
if (isset($_SESSION['weaponholster'][2][4])) {
$runthisquery.=" weapon3='" . $_SESSION['weaponholster'][2][4] . "',";
}
else {
$runthisquery.=" weapon3=NULL,";
}
//First Shield
$runthisquery.=" shield1='" . $_SESSION['shieldholster'][0][3] . "',";
//Then the second and third slots
if (isset($_SESSION['shieldholster'][1][3])) {
$runthisquery.=" shield2='" . $_SESSION['shieldholster'][1][3] . "',";
}
else {
$runthisquery.=" shield2=NULL,";
}
if (isset($_SESSION['shieldholster'][2][3])) {
$runthisquery.=" shield3='" . $_SESSION['shieldholster'][2][3] . "',";
}
else {
$runthisquery.=" shield3=NULL,";
}
$runthisquery.=" dead='no', exp='" . $_SESSION['exp'] . "', maxexp='" . $_SESSION['maxexp'] . "',";
//If there are potions in the potion holster, record them. If not, insert NULL.
//Ends with a comma (,)
$x=1;
while (isset($_SESSION['potionholster'][$x-1][2])) {
$runthisquery.=" potion$x='" . $_SESSION['potionholster'][$x-1][2] . "',";
$x++;
}
//There may not be 5 potions. If this is the case, x will not reach 5.
//If there are no potions anymore, send a null until x is 5.
while ($x<=5) {
$runthisquery.=" potion$x=NULL,";
$x++;
}
//If there are items in the item holster, record them. if not, insert NULL.
//Ends with a comma(,)
$x=1;
//print_r($_SESSION['itemholster']);
while (isset($_SESSION['itemholster'][$x-1][2])) {
//echo "while";
$runthisquery.=" item$x='" . $_SESSION['itemholster'][$x-1][2] . "',";
$x++;
}
//There might not be 5 items. If this is the case, x will not reach 5.
//If there are no more items, send a null until x is 5.
while ($x<=5) {
$runthisquery.=" item$x=NULL,";
$x++;
}
$runthisquery.=" weaponequipped='" . $_SESSION['weaponequippedID'] . "', shieldequipped='" . $_SESSION['shieldequippedID'] . "', gold='" . $_SESSION['gold'] . "', userID='" . $_SESSION['userID'] . "',";
//Quest Stuff
$runthisquery.=" questID='" . $_SESSION['questID'] . "', queststep='" . $_SESSION['queststep'] . "',";
//Gender Stuff
$runthisquery.=" gender='" . $_SESSION['gender'] . "',";
//Fist/barearms stuff (just in case)
$runthisquery.=" fisttype='" . $_SESSION['weaponholster'][0][3] . "', barearmstype='" . $_SESSION['shieldholster'][0][2] . "' ";
$runthisquery.="WHERE name='" . $_SESSION['name'] . "'";
//echo $runthisquery;
}
//If else, return an error.
else {
echo "This shouldn't happen. Contact the admin.";
exit;
}
mysql_query($runthisquery);
if (!$runthisquery) {
die('Error: ' . mysql_error());
}
//echo $runthisquery;
/*$savecurrentcharacterquery="UPDATE users SET characterID='" . $_SESSION['characterID'] . "' WHERE username='" . $_SESSION['username'] . "'";
mysql_query($savecurrentcharacterquery);*/
mysql_close($con);
//Necessary?
/*unset($_SESSION["name"]);
if (isset($_SESSION["monstername"])) {
unset($_SESSION["monstername"]);
}*/
//Must save the username to keep the user logged in
/*$username=$_SESSION["username"];
session_destroy();
//heh
session_start();
$_SESSION["username"]=$username;*/
}
?>