Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Fixed server list persistance and coutndown module issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Supernova4422 committed Jan 23, 2017
1 parent 15f7c38 commit d598a09
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 84 deletions.
36 changes: 36 additions & 0 deletions ServerModuleTests/Properties/AssemblyInfo.cs
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ServerModuleTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ServerModuleTests")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("f9480911-3993-4ae3-8f49-d2c5a3a17172")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
83 changes: 83 additions & 0 deletions ServerModuleTests/ServerModuleTests.csproj
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F9480911-3993-4AE3-8F49-D2C5A3A17172}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ServerModuleTests</RootNamespace>
<AssemblyName>ServerModuleTests</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
17 changes: 17 additions & 0 deletions ServerModuleTests/UnitTest1.cs
@@ -0,0 +1,17 @@
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SteamBotLite;

namespace SteamBotLite
{
[TestClass]
public class UnitTest1
{

[TestMethod]
public void TestMethod1()
{
ServerModule serverModule = new ServerModule(this, jsconfig);
}
}
}
24 changes: 7 additions & 17 deletions UserHandlers/VBot/VBot.cs
Expand Up @@ -24,7 +24,7 @@ class VBot : UserHandler , HTMLFileFromArrayListiners
ImpNaoModule impnaomodule;
ServerListHolder serverlistmodule;
CountDownModule countdownmodule;
MapWebServer WebServer;
MapWebServer WebServer;

public UsersModule usersModule;

Expand All @@ -44,45 +44,34 @@ class VBot : UserHandler , HTMLFileFromArrayListiners
/// <param name="SteamConnectionHandler"></param>
public VBot()
{
Console.WriteLine("Vbot Initialised");
Console.WriteLine("VBot Initialised");
Console.WriteLine("Loading modules and stuff");

MapChangeEventListiners = new List<ServerMapChangeListiner>();
HTMLParsers = new List<HTMLFileFromArrayListiners>();

// loading modules
WebServer = new MapWebServer(this, jsconfig);
HTMLParsers.Add(WebServer);

mapModule = new MapModule(this, jsconfig);

serverlistmodule = new ServerListHolder(this, jsconfig);
MapChangeEventListiners.Add(serverlistmodule);

motdModule = new MotdModule(this, jsconfig);

serverModule = new ServerModule(this, jsconfig);
usersModule = new UsersModule(this, jsconfig);
replyModule = new RepliesModule(this, jsconfig);

searchModule = new SearchModule(this, jsconfig);
adminmodule = new AdminModule(this, jsconfig);

countdownmodule = new CountDownModule(this, jsconfig);


ModuleList = new List<BaseModule> { motdModule,mapModule,serverModule,usersModule,replyModule,adminmodule,searchModule, WebServer, serverlistmodule , countdownmodule };

Console.WriteLine("Modules loaded and ModuleList intitialised");

//We run this to allow the modules to partake in actions requiring all to be loaded
foreach (BaseModule module in ModuleList)
{
module.OnAllModulesLoaded();
}




OnMaplistchange(mapModule.mapList);

}

public override void OnLoginCompleted(object sender, EventArgs e)
Expand Down Expand Up @@ -137,6 +126,7 @@ public void Disablemodule(string ModuleToRemove)
ModuleList.RemoveAt(EntryToRemove);
}
}

public void Enablemodule(string ModuleToAdd)
{
Type T = Type.GetType("SteamBotLite." + ModuleToAdd); //We attempt to translate the string to an existing type
Expand Down Expand Up @@ -204,9 +194,9 @@ public void OnMaplistchange(ObservableCollection<MapModule.Map> maplist, object
// WebServer.MapListUpdate(maplist);
}
}

public void ServerUpdated(object sender, ServerModule.ServerInfo args)
{
Console.WriteLine("Entered VBot");
if (MapChangeEventListiners.Count > 0 )
{
foreach(ServerMapChangeListiner Listiner in MapChangeEventListiners)
Expand Down
1 change: 1 addition & 0 deletions UserHandlers/VBot/VBot/BaseModule.cs
Expand Up @@ -38,6 +38,7 @@ public BaseModule(VBot bot, Dictionary<string, object> Jsconfig)
public void savePersistentData()
{
string jsonData = getPersistentData();

if (Directory.Exists(ModuleSavedDataFilePath()))
{
System.IO.File.WriteAllText(ModuleSavedDataFilePath(), jsonData);
Expand Down
8 changes: 4 additions & 4 deletions UserHandlers/VBot/VBot/Modules/CountDownModule.cs
Expand Up @@ -15,7 +15,7 @@ class CountDownModule : MotdModule

public override string GetName()
{
return "!Countdown";
return "Countdown";
}
public override int DefaultPostCountLimit()
{
Expand All @@ -35,9 +35,9 @@ public override void MotdPost(object sender, EventArgs e)

string hours = (hoursdata.ToString().PadLeft(2, '0'));
string minutes = ((postCountLimit - postCount) % 60).ToString().PadLeft(2, '0');
message = hours + ":" + minutes;

userhandler.SetStatusmessageEvent(message);
string StatusMessage = hours + ":" + minutes + " " + base.message;
userhandler.SetStatusmessageEvent(StatusMessage);

postCount++;
if (postCount > postCountLimit)
Expand Down
3 changes: 2 additions & 1 deletion UserHandlers/VBot/VBot/Modules/Map.cs
Expand Up @@ -51,6 +51,7 @@ public override void OnAllModulesLoaded()

void MapChange(object sender, NotifyCollectionChangedEventArgs args)
{

userhandler.OnMaplistchange(mapList, sender, args);
ConvertMaplistToTable();
}
Expand Down Expand Up @@ -132,7 +133,7 @@ public void OnMapChange(ServerModule.ServerInfo args)
Map map = mapList.FirstOrDefault(x => x.Filename == args.currentMap);


if (map != null)
if (map != null && args.playerCount > 8)
{
ChatroomEntity Submitter = new ChatroomEntity(map.Submitter,ChatroomEntity.Individual.User,null);
Console.WriteLine("Found map, sending message to {0}", Submitter);
Expand Down
7 changes: 1 addition & 6 deletions UserHandlers/VBot/VBot/Modules/MapWebServer.cs
Expand Up @@ -29,18 +29,13 @@ public MapWebServer(VBot bot, Dictionary<string, object> Jsconfig) : base(bot, J

try
{

WebsiteFilesDirectory = config["FilesDirectory"].ToString();

Console.WriteLine("Directory set to: {0}", WebsiteFilesDirectory);
header = System.IO.File.ReadAllText(Path.Combine(WebsiteFilesDirectory, config["HeaderFileName"].ToString()));

trailer = System.IO.File.ReadAllText(Path.Combine(WebsiteFilesDirectory, config["TrailerFileName"].ToString()));


StartWebServer(config["Address"].ToString());

//StartWebServer(config["Address"].ToString());
bot.HTMLParsers.Add(this);
}
catch (Exception exception)
{
Expand Down
23 changes: 12 additions & 11 deletions UserHandlers/VBot/VBot/Modules/Motd.cs
Expand Up @@ -24,7 +24,7 @@ public virtual int DefaultPostCountLimit()

public virtual string GetName ()
{
return "!MOTD";
return "MOTD";
}

MOTDITEM StatusMessageHolder;
Expand Down Expand Up @@ -62,7 +62,7 @@ public override string getPersistentData()
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("motd", message);
data.Add("count", postCount.ToString());

data.Add("PostLimit", postCountLimit.ToString());
return JsonConvert.SerializeObject(data);
}

Expand All @@ -73,6 +73,7 @@ public override void loadPersistentData()
Dictionary<string, string> data = JsonConvert.DeserializeObject<Dictionary<string, string>>(System.IO.File.ReadAllText(this.GetType().Name + ".json"));
message = data["motd"];
postCount = int.Parse(data["count"]);
postCountLimit = int.Parse(data["PostLimit"]);
}
catch
{
Expand Down Expand Up @@ -164,7 +165,7 @@ private void CountDownPost(object sender, EventArgs e)
abstract public class MotdCommand : BaseCommand
{
protected MotdModule motd;
public MotdCommand(VBot bot, string command, MotdModule motd) : base(bot, motd.GetName() + command)
public MotdCommand(VBot bot, string command, MotdModule motd) : base(bot,"!" + motd.GetName() + command)
{
this.motd = motd;
}
Expand Down Expand Up @@ -212,20 +213,20 @@ protected override string exec(MessageEventArgs Msg, string param)
motd.postCount = 0;
motd.postCountLimit = motd.DefaultPostCountLimit();
motd.savePersistentData();
return "MOTD Set to: " + motd.message;
return motd.GetName() + " Set to: " + motd.message;
}
}

private class SetExtended : MotdCommand
{
public SetExtended(VBot bot, MotdModule motd) : base(bot, "setextended", motd) { }
public SetExtended(VBot bot, MotdModule motd) : base(bot, "extendedset", motd) { }
protected override string exec(MessageEventArgs Msg, string param)
{
string[] parameters = param.Split(new char[] { ' ' }, 2);

if (parameters.Length < 2)
{
return "Incorrect syntax, use: !setextendedmotd <days> <motd>";
return "Incorrect syntax, use: <Number of times to post> <motd>";
}

if (motd.message != null)
Expand All @@ -238,15 +239,15 @@ protected override string exec(MessageEventArgs Msg, string param)
}
catch
{
return "Incorrect syntax, use: !setextendedmotd <Number of Days> <motd>";
return "Incorrect syntax, use: <Number of times to post> <motd>";
}

motd.message = parameters[1];
motd.setter = Msg.Sender;
motd.postCount = 0;
motd.postCountLimit = Days * 24;
motd.postCountLimit = Days;
motd.savePersistentData();
return "MOTD Set to: " + motd.message + " | with a post limit of: " + motd.postCountLimit;
return motd.GetName() + " Set to: " + motd.message + " | with a post limit of: " + motd.postCountLimit;
}
}

Expand All @@ -268,7 +269,7 @@ private class Tick : MotdCommand
public Tick(VBot bot, MotdModule motd) : base(bot, "Tick", motd) { }
protected override string exec(MessageEventArgs Msg, string param)
{
return "MOTD displayed " + motd.postCount + " times and will display a total of " + motd.postCountLimit + " times in total";
return motd.GetName() +" displayed " + motd.postCount + " times and will display a total of " + motd.postCountLimit + " times in total";
}
}

Expand All @@ -277,7 +278,7 @@ private class Setter : MotdCommand
public Setter(VBot bot, MotdModule motd) : base(bot, "Setter", motd) { }
protected override string exec(MessageEventArgs Msg, string param)
{
return "MOTD set by " + motd.setter;
return motd.GetName() +" set by " + motd.setter;
}
}
class MOTDITEM
Expand Down

0 comments on commit d598a09

Please sign in to comment.