00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <wxdialogs/MainDialog.h>
00022 #include <wxdialogs/SettingsDialog.h>
00023 #include <common/Defines.h>
00024 #include <common/OptionsGame.h>
00025 #include <engine/ModDirs.h>
00026 #include <wx/wx.h>
00027 #include <wx/utils.h>
00028 #include <wx/dir.h>
00029 #include "ServerS.cpp"
00030
00031 extern char scorched3dAppName[128];
00032
00033 class ServerSFrame: public wxDialog
00034 {
00035 public:
00036 ServerSFrame(OptionsGame &options);
00037
00038 virtual bool TransferDataToWindow();
00039 virtual bool TransferDataFromWindow();
00040
00041 void onSettingsButton(wxCommandEvent &event);
00042 void onPublishAutoButton(wxCommandEvent &event);
00043
00044 private:
00045 DECLARE_EVENT_TABLE()
00046
00047 OptionsGame &options_;
00048 };
00049
00050 BEGIN_EVENT_TABLE(ServerSFrame, wxDialog)
00051 EVT_BUTTON(IDC_BUTTON_SETTINGS, ServerSFrame::onSettingsButton)
00052 EVT_BUTTON(IDC_PUBLISHAUTO, ServerSFrame::onPublishAutoButton)
00053 END_EVENT_TABLE()
00054
00055 ServerSFrame::ServerSFrame(OptionsGame &options) :
00056 wxDialog(getMainDialog(), -1, wxString(scorched3dAppName, wxConvUTF8),
00057 wxDefaultPosition, wxDefaultSize),
00058 options_(options)
00059 {
00060 #ifdef _WIN32
00061
00062 wxIcon icon(convertString(S3D::getDataFile("data/windows/tank2.ico")), wxBITMAP_TYPE_ICO);
00063 SetIcon(icon);
00064 #endif
00065
00066
00067 wxBoxSizer *topsizer = new wxBoxSizer(wxVERTICAL);
00068
00069
00070 createControls(this, topsizer);
00071 IDOK_CTRL->SetDefault();
00072
00073
00074 SetSizer(topsizer);
00075 topsizer->SetSizeHints(this);
00076
00077 CentreOnScreen();
00078 }
00079
00080 void ServerSFrame::onPublishAutoButton(wxCommandEvent &event)
00081 {
00082 IDC_PUBLISHIP_CTRL->SetValue(wxT("AutoDetect"));
00083 }
00084
00085 void ServerSFrame::onSettingsButton(wxCommandEvent &event)
00086 {
00087 TransferDataFromWindow();
00088
00089 showSettingsDialog(true, options_);
00090 }
00091
00092 bool ServerSFrame::TransferDataToWindow()
00093 {
00094 IDC_SERVER_PORT_CTRL->SetValue(
00095 convertString(S3D::formatStringBuffer("%i", options_.getPortNo())));
00096 IDC_SERVER_PORT_CTRL->SetToolTip(
00097 convertString(options_.getPortNoEntry().getDescription()));
00098 IDC_SERVERMANAGEMENT_PORT_CTRL->SetValue(
00099 convertString(S3D::formatStringBuffer("%i", options_.getManagementPortNo())));
00100 IDC_SERVERMANAGEMENT_PORT_CTRL->SetToolTip(
00101 convertString(options_.getManagementPortNoEntry().getDescription()));
00102 IDC_SERVER_NAME_CTRL->SetValue(
00103 convertString(options_.getServerName()));
00104 IDC_SERVER_NAME_CTRL->SetToolTip(
00105 convertString(options_.getServerNameEntry().getDescription()));
00106 IDC_PUBLISH_CTRL->SetValue(options_.getPublishServer());
00107 IDC_PUBLISH_CTRL->SetToolTip(
00108 convertString(options_.getPublishServerEntry().getDescription()));
00109 IDC_PUBLISHIP_CTRL->SetValue(
00110 convertString(options_.getPublishAddress()));
00111 IDC_PUBLISHIP_CTRL->SetToolTip(
00112 convertString(options_.getPublishAddressEntry().getDescription()));
00113 IDC_ALLOWSAME_CTRL->SetValue(options_.getAllowSameIP());
00114 IDC_ALLOWSAME_CTRL->SetToolTip(
00115 convertString(options_.getAllowSameIPEntry().getDescription()));
00116 IDC_ALLOWSAMEID_CTRL->SetValue(options_.getAllowSameUniqueId());
00117 IDC_ALLOWSAMEID_CTRL->SetToolTip(
00118 convertString(options_.getAllowSameUniqueIdEntry().getDescription()));
00119 IDC_LOGTOFILE_CTRL->SetValue(0 == strcmp("file", options_.getServerFileLogger()));
00120 IDC_LOGTOFILE_CTRL->SetToolTip(
00121 convertString(options_.getServerFileLoggerEntry().getDescription()));
00122
00123 ModDirs modDirs;
00124 if (!modDirs.loadModDirs()) S3D::dialogExit("ModFiles", "Failed to load mod files");
00125 std::list<ModInfo>::iterator itor;
00126 for (itor = modDirs.getDirs().begin();
00127 itor != modDirs.getDirs().end();
00128 itor++)
00129 {
00130 ModInfo &info = *itor;
00131 IDC_SERVER_MOD_CTRL->Append(convertString(info.getName()));
00132 }
00133 if (IDC_SERVER_MOD_CTRL->FindString(convertString(options_.getMod())) != -1)
00134 IDC_SERVER_MOD_CTRL->SetValue(convertString(options_.getMod()));
00135 else
00136 IDC_SERVER_MOD_CTRL->SetValue(wxT("none"));
00137 IDC_SERVER_MOD_CTRL->SetToolTip(
00138 convertString("The Scorched3D mod to use for this game."));
00139
00140 return true;
00141 }
00142
00143 bool ServerSFrame::TransferDataFromWindow()
00144 {
00145 options_.getPortNoEntry().setValue(atoi(IDC_SERVER_PORT_CTRL->GetValue().mb_str(wxConvUTF8)));
00146 options_.getManagementPortNoEntry().setValue(atoi(IDC_SERVERMANAGEMENT_PORT_CTRL->GetValue().mb_str(wxConvUTF8)));
00147 options_.getServerNameEntry().setValue(std::string(IDC_SERVER_NAME_CTRL->GetValue().mb_str(wxConvUTF8)));
00148 options_.getPublishServerEntry().setValue(IDC_PUBLISH_CTRL->GetValue());
00149 options_.getPublishAddressEntry().setValue(std::string(IDC_PUBLISHIP_CTRL->GetValue().mb_str(wxConvUTF8)));
00150 options_.getAllowSameIPEntry().setValue(IDC_ALLOWSAME_CTRL->GetValue());
00151 options_.getAllowSameUniqueIdEntry().setValue(IDC_ALLOWSAMEID_CTRL->GetValue());
00152 options_.getModEntry().setValue(std::string(IDC_SERVER_MOD_CTRL->GetValue().mb_str(wxConvUTF8)));
00153 options_.getServerFileLoggerEntry().setValue((IDC_LOGTOFILE_CTRL->GetValue()?"file":"none"));
00154 return true;
00155 }
00156
00157 bool showServerSDialog()
00158 {
00159 OptionsGame tmpOptions;
00160 std::string serverFileSrc = S3D::getDataFile("data/server.xml");
00161 std::string serverFileDest = S3D::getSettingsFile("server.xml");
00162 if (S3D::fileExists(serverFileDest.c_str()))
00163 {
00164 tmpOptions.readOptionsFromFile((char *) serverFileDest.c_str());
00165 }
00166 else
00167 {
00168 tmpOptions.readOptionsFromFile((char *) serverFileSrc.c_str());
00169 }
00170
00171 ServerSFrame frame(tmpOptions);
00172 if (frame.ShowModal() == wxID_OK)
00173 {
00174 tmpOptions.writeOptionsToFile((char *) serverFileDest.c_str());
00175 std::string fileName = S3D::formatStringBuffer("-startserver \"%s\"", serverFileDest.c_str());
00176 runScorched3D(fileName.c_str(), true);
00177 return true;
00178 }
00179 return false;
00180 }
00181