Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…c2-4a08-a3b7-d3cc9173df77
  • Loading branch information
FreeApophis committed Jun 3, 2010
1 parent 2d70560 commit fe136a0
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 13 deletions.
2 changes: 1 addition & 1 deletion IrcD.Net/Commands/Mode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public override void Handle(UserInfo info, List<string> args)
}
else if (args[0] == info.Nick)
{
// Modes command without any mode -> query the Mode of the Channel
// Modes command without any mode -> query the Mode of the User
if (args.Count == 1)
{
IrcDaemon.Replies.SendUserModeIs(info);
Expand Down
38 changes: 36 additions & 2 deletions IrcD.Net/IrcD.Net.Ubuntu.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
Expand Down Expand Up @@ -46,10 +61,12 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DefineConstants>TRACE;DEBUG;UBUNTU</DefineConstants>
<OutputPath>bin\DebugMono\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<DefineConstants>TRACE;UBUNTU</DefineConstants>
<OutputPath>bin\ReleaseMono\</OutputPath>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
Expand Down Expand Up @@ -167,11 +184,28 @@
<Compile Include="Utils\Logger.cs" />
<Compile Include="Utils\WildCard.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>xcopy ..\..\ircd.db . /y</PreBuildEvent>
<PreBuildEvent>
</PreBuildEvent>
</PropertyGroup>
</Project>
2 changes: 1 addition & 1 deletion IrcD.Net/Modes/ChannelModeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public bool HandleEvent(IrcCommandType ircCommand, ChannelInfo channel, UserInfo
internal void Update(UserInfo info, ChannelInfo chan, IEnumerable<string> args)
{
// In
bool? plus = (args.First().Length == 1) ? (bool?)null : true;
var plus = (args.First().Length == 1) ? (bool?)null : true;
var parameterTail = args.Skip(1);

// Out: this is the final mode message
Expand Down
17 changes: 17 additions & 0 deletions IrcD.Net/Modes/ModeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using IrcD.Modes.ChannelModes;
using IrcD.Modes.ChannelRanks;
using IrcD.Modes.UserModes;
Expand All @@ -26,8 +27,23 @@ namespace IrcD.Modes
{
class ModeFactory
{
public delegate T Construct<out T>();

private static readonly Dictionary<char, Construct<ChannelMode>> ChannelFactory = new Dictionary<char, Construct<ChannelMode>>();

public static T GetConstructor<T>() where T : Mode, new()
{
return new T();
}

public static ChannelMode GetChannelMode(char c)
{
Construct<ChannelMode> channelMode;
if (ChannelFactory.TryGetValue(c, out channelMode))
{
return channelMode.Invoke();
}

switch (c)
{
case 'b': return new ModeBan();
Expand Down Expand Up @@ -61,6 +77,7 @@ public static UserMode GetUserMode(char c)
{
case 'i': return new ModeInvisible();
case 'r': return new ModeRestricted();
case 'w': return new ModeWallops();
default: return null;
}
}
Expand Down
38 changes: 35 additions & 3 deletions IrcD.Net/Modes/UserModeList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IrcD.ServerReplies;

namespace IrcD.Modes
Expand All @@ -34,7 +34,10 @@ public bool HandleEvent(IrcCommandType ircCommand, UserInfo user, List<string> a

internal void Update(UserInfo info, IEnumerable<string> args)
{
bool plus = true;
var plus = true;
var lastprefix = ' ';
var validmode = new StringBuilder();

foreach (var modechar in args.First())
{
if (modechar == '+' || modechar == '-')
Expand All @@ -43,8 +46,37 @@ internal void Update(UserInfo info, IEnumerable<string> args)
continue;
}

var cmode = ModeFactory.GetUserMode(modechar);
var umode = ModeFactory.GetUserMode(modechar);
if (umode == null) continue;
if (plus)
{
if (!ContainsKey(umode.Char))
{
Add(umode);

if (lastprefix != '+')
{
validmode.Append(lastprefix = '+');
}
validmode.Append(umode.Char);
}
}
else
{
if (ContainsKey(umode.Char))
{
Remove(umode.Char);

if (lastprefix != '-')
{
validmode.Append(lastprefix = '-');
}
validmode.Append(umode.Char);
}
}
}

info.IrcDaemon.Send.Mode(info, info, info.Nick, validmode.ToString());
}

public string ToUserModeString()
Expand Down
2 changes: 1 addition & 1 deletion IrcD.Net/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IRCd.Net")]
[assembly: AssemblyCopyright("Copyright 2009")]
[assembly: AssemblyCopyright("Copyright 2009-2010 - Thomas Bruderer - GPL 3")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand Down
16 changes: 11 additions & 5 deletions IrcD.Net/Utils/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,30 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Diagnostics;

#if !UBUNTU
#if UBUNTU
using System.IO;
#else
using System;
using IrcD.Database;
#endif

namespace IrcD.Utils
{
class Logger
{
#if UBUNTU
static readonly TextWriter LogFile = new StreamWriter("ircd.log", true);
#endif
public static void Log(string message, int level = 4, string location = null)
{
var stackTrace = new StackTrace();
var callerFrame = stackTrace.GetFrame(1);
#if !UBUNTU
#if UBUNTU
LogFile.WriteLine(location ?? callerFrame + ": " + message);
LogFile.Flush();
#else
var entity = new Log { Level = level, Message = message, Location = location ?? callerFrame.ToString(), Time = DateTime.Now };

DatabaseCommon.Db.Logs.InsertOnSubmit(entity);
DatabaseCommon.Db.SubmitChanges();
#endif
Expand Down

0 comments on commit fe136a0

Please sign in to comment.