source: trunk/www/Application/Model/Emulator.php@ 78

Last change on this file since 78 was 78, checked in by george, 16 years ago
  • Upraveno: Zrušeny samostatné include soubory a správně vloženy přímé závislosti pomocí include_once do všech souborů. Takto se budou načítat jen ty třídy, které jsou skutenčě potřeba.
  • Upraveno: Aplikace se nyní inicializuje přes soubor Application.php, kde je vložena třída odvozená z třídy System. Hlavní soubor index.php se pak odkazuje na soubor aplikace.
  • Objekty Database, Config a Translation jsou nyní lokální v rámci třídy System.
  • Přidáno: Třída pro odesílání pošty. Použita v třídě User.
File size: 3.4 KB
Line 
1<?php
2
3include_once(dirname(__FILE__).'/../../Base/Model.php');
4
5class Emulator extends Model
6{
7 var $Id;
8 var $Emulator;
9 var $Task;
10
11 function __construct($Database, $Id)
12 {
13 $this->Database = $Database;
14 $this->Task = new Task($Database);
15 $this->Id = $Id;
16 $DbResult = $this->Database->query('SELECT * FROM `Emulator` WHERE `Id`='.$Id);
17 $this->Emulator = $DbResult->fetch_assoc();
18 $DbResult = $this->Database->query('SELECT * FROM `Client` WHERE `Id`='.$this->Emulator['Client']);
19 $this->Emulator['Client'] = $DbResult->fetch_assoc();
20 }
21
22 function Add()
23 {
24 $EmulatorDir = '../emulator/'.$this->Id.'/';
25 if(!file_exists($EmulatorDir)) mkdir($EmulatorDir, 0777, true);
26
27 //$this->AddTask('Vytvoření nového emulátoru', array(
28 // 'ln -s wowclient/'.$this->Emulator['Client']['Version'].'/maps emulator/'.$this->Emulator['Id'].'/mangos/maps',
29 // 'ln -s wowclient/'.$this->Emulator['Client']['Version'].'/dbc emulator/'.$this->Emulator['Id'].'/mangos/dbc',
30 //));
31 $this->Download();
32 $this->Compile();
33 }
34
35 function Download()
36 {
37 global $Config;
38
39 $this->Lock();
40 $this->Task->Add('Stažení emulátoru', array(
41 'php www/shell.php EmulatorLock '.$this->Id,
42 'mkdir '.$Config['BaseDir'].'emulator/'.$this->Id.'/',
43 'cd '.$Config['BaseDir'].'emulator/'.$this->Id.'/',
44 'git clone git://github.com/mangos/mangos.git source',
45 'cd source',
46 'git checkout '.$this->Emulator['CommitHash'],
47 'mkdir src/bindings/ScriptDev2',
48 'svn checkout -r '.$this->Emulator['ScriptDev2Revision'].' https://scriptdev2.svn.sourceforge.net/svnroot/scriptdev2/ src/bindings/ScriptDev2',
49 'git apply src/bindings/ScriptDev2/patches/'.$this->Emulator['ScriptDev2PatchFileName'],
50 'cd ../../..',
51 'php www/shell.php EmulatorUnLock '.$this->Id,
52 ));
53 }
54
55 function Compile()
56 {
57 global $Config;
58
59 $this->Lock();
60 $this->Task->Add('Překlad emulátoru', array(
61 'php www/shell.php EmulatorLock '.$this->Id,
62 'cd '.$Config['BaseDir'].'emulator/'.$this->Id.'/source',
63 'autoreconf -ifv',
64 'mkdir objdir',
65 'cd objdir',
66 'export CFLAGS="-g -ggdb '.$Config['CompilerParameters'].'"',
67 'export CXXFLAGS="-g -ggdb '.$Config['CompilerParameters'].'"',
68 '../configure --prefix='.$Config['BaseDir'].'emulator/'.$this->Id.'/ --enable-cli --enable-ra',
69 'make',
70 'make install',
71 'cd ../../../..',
72 'php www/shell.php EmulatorUnLock '.$this->Id,
73 ));
74 }
75
76 function ExtractMaps()
77 {
78 $this->Lock();
79 $this->Task->Add('Vygenerování souborů map', array(
80 'php www/shell.php EmulatorLock '.$this->Id,
81 'cd wowclient/'.$this->Emulator['Client']['Version'].'/client',
82 'wine emulator/'.$this->Id.'/source/contrib/extractor/ad.exe',
83 'mv wowclient/'.$this->Emulator['Client']['Version'].'/client/dbc wowclient/'.$this->Emulator['Client']['Version'].'/',
84 'mv wowclient/'.$this->Emulator['Client']['Version'].'/client/maps wowclient/'.$this->Emulator['Client']['Version'].'/',
85 'cd ../../..',
86 'php www/shell.php EmulatorUnLock '.$this->Id,
87 ));
88 return('Požadavek na vygenerování map zařazen.');
89 }
90
91 function Lock()
92 {
93 $this->Database->update('Emulator', 'Id='.$this->Id, array('Lock' => 1));
94 }
95
96 function UnLock()
97 {
98 $this->Database->update('Emulator', 'Id='.$this->Id, array('Lock' => 0));
99 }
100}
101
102?>
Note: See TracBrowser for help on using the repository browser.