626
659
// std::cout << line << " lines read.\n";
629
tString tConfItemBase::FindConfigItem(tString name)
631
tConfItemMap & confmap = ConfItemMap();
632
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
634
tConfItemBase * ci = (*iter).second;
636
command << ci->title.ToLower();
637
if (command.Contains(name.ToLower()))
639
if (command.StartsWith(name.ToLower()))
648
/** LISTING BEGIN **/
649
// writes the list of all commands and their help to config_all.cfg in the var directory
650
void tConfItemBase::WriteAllToFile()
652
tConfItemMap & confmap = ConfItemMap();
662
//Stolen from 0.4. Needed for "TOGGLE" function.
663
tConfItemBase *tConfItemBase::FindConfigItem2(tString const &name) {
664
tConfItemMap & confmap = ConfItemMap();
665
tConfItemMap::iterator iter = confmap.find( name.ToUpper() );
666
if ( iter != confmap.end() ) {
673
tString tConfItemBase::FindConfigItem(tString name)
675
tConfItemMap & confmap = ConfItemMap();
676
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
678
tConfItemBase * ci = (*iter).second;
680
command << ci->title.ToLower();
681
if (command.Contains(name.ToLower()))
683
if (command.StartsWith(name.ToLower()))
692
/** LISTING BEGIN **/
693
// writes the list of all commands and their help to config_all.cfg in the var directory
694
void tConfItemBase::WriteAllToFile()
696
tConfItemMap & confmap = ConfItemMap();
655
699
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
657
701
tConfItemBase * ci = (*iter).second;
658
702
if (static_cast<int>(strlen(ci->title)) > sim_maxlen)
659
703
sim_maxlen = strlen(ci->title);
663
if ( tDirectories::Var().Open(w, "config_all.cfg"))
665
/*w << "{| border=\"2\" cellspacing=\"0\" cellpadding=\"4\" rules=\"all\" style=\"margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse; background-color:#F9F9F9; font-size:95%; empty-cells:show;\"\n";
707
if ( tDirectories::Var().Open(w, "config_all.cfg"))
709
/*w << "{| border=\"2\" cellspacing=\"0\" cellpadding=\"4\" rules=\"all\" style=\"margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse; background-color:#F9F9F9; font-size:95%; empty-cells:show;\"\n";
671
715
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
673
717
tConfItemBase * ci = (*iter).second;
674
tString help ( ci->help );
678
// fetch the value set for this setting.
681
mess << ci->title << " ";
683
mess.SetPos( sim_maxlen+2, false );
718
tString help ( ci->help );
722
// fetch the value set for this setting.
725
mess << ci->title << " ";
727
mess.SetPos( sim_maxlen+2, false );
684
728
mess << value << " ";
690
/*w << "| " << ci->title << " || " << value << " || " << help << "\n";
734
/*w << "| " << ci->title << " || " << value << " || " << help << "\n";
698
static void sg_ListAllCommands(std::istream &s)
700
tConfItemBase::WriteAllToFile();
702
static tConfItemFunc sg_ListAllCommandsConf("LIST_ALL_COMMANDS", &sg_ListAllCommands);
706
/** LISTING ACCESS_LEVEL BEGIN **/
707
// writes the list of all commands and their help to config_all_levels.cfg in the var directory
708
void tConfItemBase::WriteAllLevelsToFile()
710
tConfItemMap & confmap = ConfItemMap();
742
static void sg_ListAllCommands(std::istream &s)
744
tConfItemBase::WriteAllToFile();
746
static tConfItemFunc sg_ListAllCommandsConf("LIST_ALL_COMMANDS", &sg_ListAllCommands);
750
/** LISTING ACCESS_LEVEL BEGIN **/
751
// writes the list of all commands and their help to config_all_levels.cfg in the var directory
752
void tConfItemBase::WriteAllLevelsToFile()
754
tConfItemMap & confmap = ConfItemMap();
713
757
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
715
759
tConfItemBase * ci = (*iter).second;
716
760
if (static_cast<int>(strlen(ci->title)) > sim_maxlen)
717
761
sim_maxlen = strlen(ci->title);
721
if ( tDirectories::Var().Open(w, "config_all_levels.cfg"))
765
if ( tDirectories::Var().Open(w, "config_all_levels.cfg"))
723
767
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
725
769
tConfItemBase * ci = (*iter).second;
726
tString help ( ci->help );
770
tString help ( ci->help );
730
774
mess << "ACCESS_LEVEL ";
731
mess << ci->title << " ";
775
mess << ci->title << " ";
733
//mess.SetPos( sim_maxlen+2, false );
734
mess << ci->requiredLevel;
777
//mess.SetPos( sim_maxlen+2, false );
778
mess << ci->requiredLevel;
735
779
mess.SetPos( sim_maxlen+5, false );
746
static void sg_ListAllCommandsLevels(std::istream &s)
748
tConfItemBase::WriteAllLevelsToFile();
750
static tConfItemFunc sg_ListAllCommandsLevelsConf("LIST_ALL_COMMANDS_LEVELS", &sg_ListAllCommandsLevels);
752
/** LISTING ACCESS_LEVEL END **/
754
/** SET ALL ACCESS_LEVEL BEGIN **/
755
void tConfItemBase::SetAllAccessLevel(int newLevel)
757
tConfItemMap & confmap = ConfItemMap();
758
tAccessLevel level = static_cast< tAccessLevel >( newLevel );
760
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
762
tConfItemBase * ci = (*iter).second;
763
ci->requiredLevel = level;
767
message << "All access levels of commands have been changed to " << tCurrentAccessLevel::GetName(level) << "!\n";
771
static void st_SetCommandsAccessLevel(std::istream &s)
776
int newLevel = atoi(levelStr);
777
tConfItemBase::SetAllAccessLevel(newLevel);
779
static tConfItemFunc st_SetCommandsAccessLevelConf("SET_COMMANDS_ACCESSLEVEL", &st_SetCommandsAccessLevel);
780
/** SET ALL ACCESS_LEVEL END **/
782
void tConfItemBase::WriteChangedToFile()
784
tConfItemMap & confmap = ConfItemMap();
790
static void sg_ListAllCommandsLevels(std::istream &s)
792
tConfItemBase::WriteAllLevelsToFile();
794
static tConfItemFunc sg_ListAllCommandsLevelsConf("LIST_ALL_COMMANDS_LEVELS", &sg_ListAllCommandsLevels);
796
/** LISTING ACCESS_LEVEL END **/
798
/** SET ALL ACCESS_LEVEL BEGIN **/
799
void tConfItemBase::SetAllAccessLevel(int newLevel)
801
tConfItemMap & confmap = ConfItemMap();
802
tAccessLevel level = static_cast< tAccessLevel >( newLevel );
804
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
806
tConfItemBase * ci = (*iter).second;
807
ci->requiredLevel = level;
811
message << "All access levels of commands have been changed to " << tCurrentAccessLevel::GetName(level) << "!\n";
815
static void st_SetCommandsAccessLevel(std::istream &s)
820
int newLevel = atoi(levelStr);
821
tConfItemBase::SetAllAccessLevel(newLevel);
823
static tConfItemFunc st_SetCommandsAccessLevelConf("SET_COMMANDS_ACCESSLEVEL", &st_SetCommandsAccessLevel);
824
/** SET ALL ACCESS_LEVEL END **/
826
void tConfItemBase::WriteChangedToFile()
828
tConfItemMap & confmap = ConfItemMap();
787
831
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
789
833
tConfItemBase * ci = (*iter).second;
790
834
if (static_cast<int>(strlen(ci->title)) > sim_maxlen)
791
835
sim_maxlen = strlen(ci->title);
795
if ( tDirectories::Var().Open(w, "config_changed.cfg"))
839
if ( tDirectories::Var().Open(w, "config_changed.cfg"))
797
841
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
799
tConfItemBase * ci = (*iter).second;
800
if (!ci->changed) continue;
802
tString help ( ci->help );
806
// fetch the value set for this setting.
809
mess << ci->title << " ";
811
mess.SetPos( sim_maxlen+2, false );
843
tConfItemBase * ci = (*iter).second;
844
if (!ci->changed) continue;
846
tString help ( ci->help );
850
// fetch the value set for this setting.
853
mess << ci->title << " ";
855
mess.SetPos( sim_maxlen+2, false );
812
856
mess << value << " ";
823
void tConfItemBase::DownloadSettings_Go(nMessage &m)
825
// download the config if this is a client
826
if (sn_GetNetState() == nCLIENT)
830
if ((m_title == "DOWNLOAD_BEGIN") && m.End())
832
con << "Downloading config from server...\n";
834
// truncate the file for fresh settings
836
if ( tDirectories::Var().Open(o, "server_settings.cfg", std::ios::trunc) ) {}
840
else if ((m_title == "DOWNLOAD_END") && m.End())
842
con << "Download complete!\n";
849
if (tDirectories::Var().Open(o, "server_settings.cfg", std::ios::app))
851
o << m_title << " " << m_value << "\n";
857
static nDescriptor downloadSettings(61,tConfItemBase::DownloadSettings_Go, "download settings");
859
void tConfItemBase::DownloadSettings_To(int peer)
861
// transfer the settings to the requested client
862
// Client ID must be greater than 0 for it to work
863
if ((sn_GetNetState() == nSERVER) && (peer > 0))
867
void tConfItemBase::DownloadSettings_Go(nMessage &m)
869
// download the config if this is a client
870
if (sn_GetNetState() == nCLIENT)
874
if ((m_title == "DOWNLOAD_BEGIN") && m.End())
876
con << "Downloading config from server...\n";
878
// truncate the file for fresh settings
880
if ( tDirectories::Var().Open(o, "server_settings.cfg", std::ios::trunc) ) {}
884
else if ((m_title == "DOWNLOAD_END") && m.End())
886
con << "Download complete!\n";
893
if (tDirectories::Var().Open(o, "server_settings.cfg", std::ios::app))
895
o << m_title << " " << m_value << "\n";
901
static nDescriptor downloadSettings(61,tConfItemBase::DownloadSettings_Go, "download settings");
903
void tConfItemBase::DownloadSettings_To(int peer)
905
// transfer the settings to the requested client
906
// Client ID must be greater than 0 for it to work
907
if ((sn_GetNetState() == nSERVER) && (peer > 0))
866
910
nMessage *m=new nMessage(downloadSettings);
867
*m << tString("DOWNLOAD_BEGIN");
911
*m << tString("DOWNLOAD_BEGIN");
871
915
tConfItemMap & confmap = ConfItemMap();
872
916
for(tConfItemMap::iterator iter = confmap.begin(); iter != confmap.end() ; ++iter)
874
tConfItemBase * item = (*iter).second;
875
if (item && item->CanSave())
918
tConfItemBase * item = (*iter).second;
919
if (item && item->CanSave())
877
921
nMessage *m=new nMessage(downloadSettings);
881
item->FetchVal(value);
925
item->FetchVal(value);
889
933
nMessage *m=new nMessage(downloadSettings);
890
*m << tString("DOWNLOAD_END");
896
tString configFileDownload("");
897
void tConfItemBase::DownloadConfig_Go(nMessage &m)
899
// download the config if this is a client
900
if (sn_GetNetState() == nCLIENT)
904
if ((c_line == "DOWNLOAD_BEGIN") && !m.End())
906
m >> configFileDownload;
907
con << "Downloading \"" << configFileDownload << "\" from server...\n";
909
// truncate the file for fresh settings
912
configFile << "public/" << configFileDownload;
913
if ( tDirectories::Config().Open(o, configFile, std::ios::trunc) ) {}
917
else if ((c_line == "DOWNLOAD_END") && m.End())
919
con << "Download complete!\n";
920
configFileDownload = "";
924
if (configFileDownload == "") return;
928
configFile << "public/" << configFileDownload;
929
if (tDirectories::Config().Open(o, configFile, std::ios::app))
937
static nDescriptor downloadConfigs(62,tConfItemBase::DownloadConfig_Go, "download config");
939
bool st_downloadConfigProcess = false;
940
void tConfItemBase::DownloadConfig_To(tString file, int peer)
942
// don't process if its under process
943
if (st_downloadConfigProcess) return;
944
st_downloadConfigProcess = true;
934
*m << tString("DOWNLOAD_END");
940
tString configFileDownload("");
941
void tConfItemBase::DownloadConfig_Go(nMessage &m)
943
// download the config if this is a client
944
if (sn_GetNetState() == nCLIENT)
948
if ((c_line == "DOWNLOAD_BEGIN") && !m.End())
950
m >> configFileDownload;
951
con << "Downloading \"" << configFileDownload << "\" from server...\n";
953
// truncate the file for fresh settings
956
configFile << "public/" << configFileDownload;
957
if ( tDirectories::Config().Open(o, configFile, std::ios::trunc) ) {}
961
else if ((c_line == "DOWNLOAD_END") && m.End())
963
con << "Download complete!\n";
964
configFileDownload = "";
968
if (configFileDownload == "") return;
972
configFile << "public/" << configFileDownload;
973
if (tDirectories::Config().Open(o, configFile, std::ios::app))
981
static nDescriptor downloadConfigs(62,tConfItemBase::DownloadConfig_Go, "download config");
983
bool st_downloadConfigProcess = false;
984
void tConfItemBase::DownloadConfig_To(tString file, int peer)
986
// don't process if its under process
987
if (st_downloadConfigProcess) return;
988
st_downloadConfigProcess = true;
946
990
// refuse to load illegal paths
947
991
if( !tPath::IsValidPath( file ) )
954
configFile << "public/" << file;
956
// transfer the settings from config to the client
957
// Client ID must be greater than 0 for it to work
958
if ((sn_GetNetState() == nSERVER) && (peer > 0) && tDirectories::Config().Open(i, configFile))
998
configFile << "public/" << file;
1000
// transfer the settings from config to the client
1001
// Client ID must be greater than 0 for it to work
1002
if ((sn_GetNetState() == nSERVER) && (peer > 0) && tDirectories::Config().Open(i, configFile))
960
1004
m = new nMessage(downloadConfigs);
961
*m << tString("DOWNLOAD_BEGIN");
967
while (!s.eof() && s.good())
1005
*m << tString("DOWNLOAD_BEGIN");
1011
while (!s.eof() && s.good())
972
1016
m = new nMessage(downloadConfigs);
979
1023
m = new nMessage(downloadConfigs);
980
*m << tString("DOWNLOAD_END");
985
st_downloadConfigProcess = false;
1024
*m << tString("DOWNLOAD_END");
1029
st_downloadConfigProcess = false;
989
1033
int tConfItemBase::AccessLevel(std::istream &s){