|
132 | 132 | switch ($itemId) { |
133 | 133 | case 'ram': |
134 | 134 | $maxRam = $config->getSetting(ConfigInterface::MAX_RAM, 1024); |
135 | | - if ($session->getInfo(UserColumns::MEMORY_LIMIT, false) >= $maxRam) { |
| 135 | + $currentRam = (int)$session->getInfo(UserColumns::MEMORY_LIMIT, false); |
| 136 | + $ramToAdd = isset($item['ram']) ? (int)$item['ram'] : 1024; |
| 137 | + if ($currentRam >= (int)$maxRam) { |
136 | 138 | $appInstance->BadRequest('You have reached the maximum RAM limit', [ |
137 | 139 | 'error_code' => 'MAX_RAM_LIMIT', |
138 | 140 | 'required' => $maxRam, |
139 | | - 'available' => $session->getInfo(UserColumns::MEMORY_LIMIT, false), |
| 141 | + 'available' => $currentRam, |
| 142 | + ]); |
| 143 | + return; |
| 144 | + } |
| 145 | + if (($currentRam + $ramToAdd) > (int)$maxRam) { |
| 146 | + $appInstance->BadRequest('This purchase would exceed your maximum RAM limit', [ |
| 147 | + 'error_code' => 'MAX_RAM_LIMIT', |
| 148 | + 'required' => $maxRam, |
| 149 | + 'available' => $currentRam, |
| 150 | + 'attempted_to_add' => $ramToAdd, |
140 | 151 | ]); |
141 | | - |
142 | 152 | return; |
143 | 153 | } |
144 | 154 | break; |
145 | 155 | case 'disk': |
146 | 156 | $maxDisk = $config->getSetting(ConfigInterface::MAX_DISK, 1024); |
147 | | - if ($session->getInfo(UserColumns::DISK_LIMIT, false) >= $maxDisk) { |
| 157 | + $currentDisk = (int)$session->getInfo(UserColumns::DISK_LIMIT, false); |
| 158 | + $diskToAdd = isset($item['disk']) ? (int)$item['disk'] : 1024; |
| 159 | + if ($currentDisk >= (int)$maxDisk) { |
148 | 160 | $appInstance->BadRequest('You have reached the maximum disk limit', [ |
149 | 161 | 'error_code' => 'MAX_DISK_LIMIT', |
150 | 162 | 'required' => $maxDisk, |
151 | | - 'available' => $session->getInfo(UserColumns::DISK_LIMIT, false), |
| 163 | + 'available' => $currentDisk, |
| 164 | + ]); |
| 165 | + return; |
| 166 | + } |
| 167 | + if (($currentDisk + $diskToAdd) > (int)$maxDisk) { |
| 168 | + $appInstance->BadRequest('This purchase would exceed your maximum disk limit', [ |
| 169 | + 'error_code' => 'MAX_DISK_LIMIT', |
| 170 | + 'required' => $maxDisk, |
| 171 | + 'available' => $currentDisk, |
| 172 | + 'attempted_to_add' => $diskToAdd, |
152 | 173 | ]); |
153 | | - |
154 | 174 | return; |
155 | 175 | } |
156 | 176 | break; |
157 | 177 | case 'cpu': |
158 | 178 | $maxCpu = $config->getSetting(ConfigInterface::MAX_CPU, 100); |
159 | | - if ($session->getInfo(UserColumns::CPU_LIMIT, false) >= $maxCpu) { |
| 179 | + $currentCpu = (int)$session->getInfo(UserColumns::CPU_LIMIT, false); |
| 180 | + $cpuToAdd = isset($item['cpu']) ? (int)$item['cpu'] : 100; |
| 181 | + if ($currentCpu >= (int)$maxCpu) { |
160 | 182 | $appInstance->BadRequest('You have reached the maximum CPU limit', [ |
161 | 183 | 'error_code' => 'MAX_CPU_LIMIT', |
162 | 184 | 'required' => $maxCpu, |
163 | | - 'available' => $session->getInfo(UserColumns::CPU_LIMIT, false), |
| 185 | + 'available' => $currentCpu, |
| 186 | + ]); |
| 187 | + return; |
| 188 | + } |
| 189 | + if (($currentCpu + $cpuToAdd) > (int)$maxCpu) { |
| 190 | + $appInstance->BadRequest('This purchase would exceed your maximum CPU limit', [ |
| 191 | + 'error_code' => 'MAX_CPU_LIMIT', |
| 192 | + 'required' => $maxCpu, |
| 193 | + 'available' => $currentCpu, |
| 194 | + 'attempted_to_add' => $cpuToAdd, |
164 | 195 | ]); |
165 | | - |
166 | 196 | return; |
167 | 197 | } |
168 | 198 | break; |
169 | 199 | case 'server_slot': |
170 | | - $maxServerSlots = $config->getSetting(ConfigInterface::MAX_SERVER_SLOTS, 1); |
171 | | - if ($session->getInfo(UserColumns::SERVER_LIMIT, false) >= $maxServerSlots) { |
| 200 | + $maxServerSlots = (int)$config->getSetting(ConfigInterface::MAX_SERVER_SLOTS, 1); |
| 201 | + $currentSlots = (int)$session->getInfo(UserColumns::SERVER_LIMIT, false); |
| 202 | + if ($currentSlots >= (int)$maxServerSlots) { |
172 | 203 | $appInstance->BadRequest('You have reached the maximum server slots limit', [ |
173 | 204 | 'error_code' => 'MAX_SERVER_SLOTS_LIMIT', |
174 | 205 | 'required' => $maxServerSlots, |
175 | | - 'available' => $session->getInfo(UserColumns::SERVER_LIMIT, false), |
| 206 | + 'available' => $currentSlots, |
| 207 | + ]); |
| 208 | + return; |
| 209 | + } |
| 210 | + $slotsToAdd = isset($item['slots']) ? (int)$item['slots'] : 1; |
| 211 | + if (($currentSlots + $slotsToAdd) > (int)$maxServerSlots) { |
| 212 | + $appInstance->BadRequest('This purchase would exceed your maximum server slots limit', [ |
| 213 | + 'error_code' => 'MAX_SERVER_SLOTS_LIMIT', |
| 214 | + 'required' => $maxServerSlots, |
| 215 | + 'available' => $currentSlots, |
| 216 | + 'attempted_to_add' => $slotsToAdd, |
176 | 217 | ]); |
177 | | - |
178 | 218 | return; |
179 | 219 | } |
180 | 220 | break; |
181 | 221 | case 'server_backup': |
182 | 222 | $maxBackups = $config->getSetting(ConfigInterface::MAX_BACKUPS, 5); |
183 | | - if ($session->getInfo(UserColumns::BACKUP_LIMIT, false) >= $maxBackups) { |
| 223 | + $currentBackups = (int)$session->getInfo(UserColumns::BACKUP_LIMIT, false); |
| 224 | + $backupsToAdd = isset($item['backups']) ? (int)$item['backups'] : 1; |
| 225 | + if ($currentBackups >= (int)$maxBackups) { |
184 | 226 | $appInstance->BadRequest('You have reached the maximum backups limit', [ |
185 | 227 | 'error_code' => 'MAX_BACKUPS_LIMIT', |
186 | 228 | 'required' => $maxBackups, |
187 | | - 'available' => $session->getInfo(UserColumns::BACKUP_LIMIT, false), |
| 229 | + 'available' => $currentBackups, |
| 230 | + ]); |
| 231 | + return; |
| 232 | + } |
| 233 | + if (($currentBackups + $backupsToAdd) > (int)$maxBackups) { |
| 234 | + $appInstance->BadRequest('This purchase would exceed your maximum backups limit', [ |
| 235 | + 'error_code' => 'MAX_BACKUPS_LIMIT', |
| 236 | + 'required' => $maxBackups, |
| 237 | + 'available' => $currentBackups, |
| 238 | + 'attempted_to_add' => $backupsToAdd, |
188 | 239 | ]); |
189 | | - |
190 | 240 | return; |
191 | 241 | } |
192 | 242 | break; |
193 | 243 | case 'server_allocation': |
194 | 244 | $maxPorts = $config->getSetting(ConfigInterface::MAX_PORTS, 2); |
195 | | - if ($session->getInfo(UserColumns::ALLOCATION_LIMIT, false) >= $maxPorts) { |
| 245 | + $currentPorts = (int)$session->getInfo(UserColumns::ALLOCATION_LIMIT, false); |
| 246 | + $portsToAdd = isset($item['ports']) ? (int)$item['ports'] : 1; |
| 247 | + if ($currentPorts >= (int)$maxPorts) { |
196 | 248 | $appInstance->BadRequest('You have reached the maximum ports limit', [ |
197 | 249 | 'error_code' => 'MAX_PORTS_LIMIT', |
198 | 250 | 'required' => $maxPorts, |
199 | | - 'available' => $session->getInfo(UserColumns::ALLOCATION_LIMIT, false), |
| 251 | + 'available' => $currentPorts, |
| 252 | + ]); |
| 253 | + return; |
| 254 | + } |
| 255 | + if (($currentPorts + $portsToAdd) > (int)$maxPorts) { |
| 256 | + $appInstance->BadRequest('This purchase would exceed your maximum ports limit', [ |
| 257 | + 'error_code' => 'MAX_PORTS_LIMIT', |
| 258 | + 'required' => $maxPorts, |
| 259 | + 'available' => $currentPorts, |
| 260 | + 'attempted_to_add' => $portsToAdd, |
200 | 261 | ]); |
201 | | - |
202 | 262 | return; |
203 | 263 | } |
204 | 264 | break; |
205 | 265 | case 'server_database': |
206 | 266 | $maxDatabases = $config->getSetting(ConfigInterface::MAX_DATABASES, 1); |
207 | | - if ($session->getInfo(UserColumns::DATABASE_LIMIT, false) >= $maxDatabases) { |
| 267 | + $currentDatabases = (int)$session->getInfo(UserColumns::DATABASE_LIMIT, false); |
| 268 | + $databasesToAdd = isset($item['databases']) ? (int)$item['databases'] : 1; |
| 269 | + if ($currentDatabases >= (int)$maxDatabases) { |
208 | 270 | $appInstance->BadRequest('You have reached the maximum databases limit', [ |
209 | 271 | 'error_code' => 'MAX_DATABASES_LIMIT', |
210 | 272 | 'required' => $maxDatabases, |
211 | | - 'available' => $session->getInfo(UserColumns::DATABASE_LIMIT, false), |
| 273 | + 'available' => $currentDatabases, |
| 274 | + ]); |
| 275 | + return; |
| 276 | + } |
| 277 | + if (($currentDatabases + $databasesToAdd) > (int)$maxDatabases) { |
| 278 | + $appInstance->BadRequest('This purchase would exceed your maximum databases limit', [ |
| 279 | + 'error_code' => 'MAX_DATABASES_LIMIT', |
| 280 | + 'required' => $maxDatabases, |
| 281 | + 'available' => $currentDatabases, |
| 282 | + 'attempted_to_add' => $databasesToAdd, |
212 | 283 | ]); |
213 | | - |
214 | 284 | return; |
215 | 285 | } |
216 | 286 | break; |
|
0 commit comments