[arthea] r472 committed - [No log message]

2 views
Skip to first unread message

art...@googlecode.com

unread,
Apr 22, 2011, 12:58:05 PM4/22/11
to arthea-...@googlegroups.com
Revision: 472
Author: c0der78
Date: Fri Apr 22 09:57:31 2011
Log: [No log message]
http://code.google.com/p/arthea/source/detail?r=472

Added:
/trunk/ArtheaEngine/Model/Forum.cs
/trunk/ArtheaServer/Commands/ForumCommand.cs
Deleted:
/trunk/ArtheaEngine/Model/Board.cs
Modified:
/trunk/ArtheaEngine/ArtheaEngine.csproj
/trunk/ArtheaEngine/Model/Note.cs
/trunk/ArtheaEngine/Model/Player.cs
/trunk/ArtheaServer/ArtheaServer.csproj

=======================================
--- /dev/null
+++ /trunk/ArtheaEngine/Model/Forum.cs Fri Apr 22 09:57:31 2011
@@ -0,0 +1,293 @@
+namespace ArtheaEngine.Model
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Collections.Specialized;
+ using System.Data;
+ using System.Linq;
+ using System.Reflection;
+ using System.Text;
+
+ using NLog;
+
+ #region Enumerations
+
+ [Flags]
+ public enum ForumPermissions
+ {
+ /// <summary>
+ /// No permissions, all can read/write
+ /// </summary>
+ None,
+ /// <summary>
+ /// Only person in to or from fields
+ /// </summary>
+ Personal,
+ /// <summary>
+ /// admin can read/write
+ /// </summary>
+ Admin
+ }
+
+ #endregion Enumerations
+
+ public class AnnounceForum : Forum
+ {
+ #region Properties
+
+ public override string Description
+ {
+ get { return "Forum for announcements from administrators."; }
+ }
+
+ public override int Id
+ {
+ get { return 1; }
+ }
+
+ public override string Name
+ {
+ get { return "Announce"; }
+ }
+
+ public override ForumPermissions ReadPermission
+ {
+ get { return ForumPermissions.None; }
+ }
+
+ public override ForumPermissions WritePermission
+ {
+ get { return ForumPermissions.Admin; }
+ }
+
+ #endregion Properties
+ }
+
+ /// <summary>
+ /// Implementation of Forum.
+ /// </summary>
+ public abstract class Forum : IEntity<int>, IPersistent
+ {
+ #region Fields
+
+ public static readonly HashSet<Forum> List = new HashSet<Forum>();
+
+ #endregion Fields
+
+ #region Constructors
+
+ static Forum()
+ {
+ var assm = Assembly.GetExecutingAssembly();
+
+ using (var conn = ArtheaHelper.NewConnection())
+ {
+ foreach (var t in assm.GetTypes())
+ {
+ if (t.IsSubclassOf(typeof(Forum)))
+ {
+ var b = (Forum)Activator.CreateInstance(t);
+ b.Load(conn);
+ List.Add(b);
+ }
+ }
+ }
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Forum"/> class.
+ /// </summary>
+ public Forum()
+ {
+ Notes = new ObservableCollection<Note>();
+ Notes.CollectionChanged +=
ArtheaHelper.CollectionChangedHandler<Note>((n, a) =>
+ {
+ n.Forum = a ? this : null;
+ });
+ }
+
+ #endregion Constructors
+
+ #region Properties
+
+ public abstract string Description
+ {
+ get;
+ }
+
+ public abstract int Id
+ {
+ get;
+ }
+
+ public abstract string Name
+ {
+ get;
+ }
+
+ public ObservableCollection<Note> Notes
+ {
+ get; set;
+ }
+
+ public abstract ForumPermissions ReadPermission
+ {
+ get;
+ }
+
+ public abstract ForumPermissions WritePermission
+ {
+ get;
+ }
+
+ #endregion Properties
+
+ #region Methods
+
+ public static Note FindNote(long id)
+ {
+ foreach (var b in List)
+ {
+ var n = b.Notes.SingleOrDefault(x => x.Id == id);
+
+ if (n != null) return n;
+ }
+ return null;
+ }
+
+ public static Forum Lookup(int id)
+ {
+ return List.FirstOrDefault(x => x.Id == id);
+ }
+
+ public bool ReadableBy(Character ch)
+ {
+ if (ReadPermission.HasFlag(ForumPermissions.Admin) && ch.Level
< ArtheaHelper.Immortal)
+ return false;
+
+ return true;
+ }
+
+ /// <summary>
+ /// Returns the number of unread notes for a player on this Forum.
+ /// </summary>
+ /// <param name="player">The player.</param>
+ /// <returns>the number of unread notes</returns>
+ public int CountUnreadNotes(Player player)
+ {
+ if (ReadPermission.HasFlag(ForumPermissions.Admin) &&
(player.Account.Flags.HasFlag(AccountFlag.Admin)))
+ return 0;
+
+ int count = 0;
+
+ foreach (Note n in Notes)
+ {
+ if (player.HasReadNote(n) ||
+ !n.ReadableBy(player))
+ {
+ continue;
+ }
+
+ ++count;
+ }
+
+ return count;
+ }
+
+ public bool Delete(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("delete_forum");
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ return cmd.ExecuteNonQuery() == 1;
+ }
+
+ /// <summary>
+ /// Gets the next unread.
+ /// </summary>
+ /// <param name="player">The player.</param>
+ /// <returns></returns>
+ public Note GetNextUnreadNote(Player player)
+ {
+ if (ReadPermission.HasFlag(ForumPermissions.Admin)
&& !player.Account.Flags.HasFlag(AccountFlag.Admin))
+ return null;
+
+ foreach (Note n in Notes)
+ {
+ if (player.HasReadNote(n) ||
+ !n.ReadableBy(player))
+ {
+ continue;
+ }
+
+ return n;
+ }
+
+ return null;
+ }
+
+ public bool Load(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("read_forum");
+ cmd.AddParameter("@id", DbType.Int32, Id);
+
+ return this.Load(cmd);
+ }
+
+ public int MapRow(IDataRecord reader)
+ {
+ return 0;
+ }
+
+ public bool Save(IDbConnection conn)
+ {
+ var cmd = conn.CreateCommand("save_forum");
+
+ cmd.AddParameter("@id", DbType.Int32, Id);
+ cmd.AddParameter("@name", DbType.String, Name);
+ cmd.AddParameter("@descr", DbType.String, Description);
+ cmd.AddParameter("@read_perm", DbType.String,
ReadPermission.ToString());
+ cmd.AddParameter("@write_perm", DbType.String,
WritePermission.ToString());
+
+ return cmd.ExecuteNonQuery() > 0;
+ }
+
+ /// <summary>
+ /// Shows the note list to.
+ /// </summary>
+ /// <param name="player">The player.</param>
+ public void ShowNoteListTo(Player player)
+ {
+ StringCollection columns = new StringCollection();
+
+ var count = 0;
+
+ foreach(var note in Notes)
+ {
+ if (!note.ReadableBy(player))
+ continue;
+
+ columns.Add(string.Format("{0}{1,-2}> {2} ({3})",
+
player.HasReadNote(note) ? "~R*~x" : " ",
+ (count + 1), note.Subject,
note.From));
+ count++;
+ }
+
+ Columns.Show(player, 2, columns);
+ }
+
+ /// <summary>
+ /// Returns a <see cref="T:System.String"></see> that represents
the current <see cref="T:System.Object"></see>.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="T:System.String"></see> that represents the
current <see cref="T:System.Object"></see>.
+ /// </returns>
+ public override string ToString()
+ {
+ return Name;
+ }
+
+ #endregion Methods
+ }
+}
=======================================
--- /dev/null
+++ /trunk/ArtheaServer/Commands/ForumCommand.cs Fri Apr 22 09:57:31 2011
@@ -0,0 +1,41 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using ArtheaEngine.Model;
+using ArtheaEngine;
+
+namespace ArtheaServer.Commands
+{
+ public class ForumCommand : Command
+ {
+ public ForumCommand()
+ : base("forum", "Command to read/write notes on the forums.",
1)
+ { }
+
+ public override void Execute(Character ch, Argument argument)
+ {
+ if (!argument)
+ {
+ int i = 1;
+ foreach (var f in Forum.List)
+ {
+ if(f.ReadableBy(ch))
+ ch.WriteLine("~R{0:2}> ~G{1}~W: {2}~x", i++,
f.Name, f.Description);
+ }
+ }
+ }
+ }
+
+ public class NoteCommand : Command
+ {
+ public NoteCommand()
+ : base("note", "Command to read/write notes.", 1)
+ { }
+
+ public override void Execute(Character ch, Argument argument)
+ {
+
+ }
+ }
+}
=======================================
--- /trunk/ArtheaEngine/Model/Board.cs Tue Apr 19 15:57:05 2011
+++ /dev/null
@@ -1,300 +0,0 @@
-namespace ArtheaEngine.Model
-{
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Collections.Specialized;
- using System.Data;
- using System.Linq;
- using System.Reflection;
- using System.Text;
-
- using NLog;
-
- #region Enumerations
-
- [Flags]
- public enum BoardPermissions
- {
- /// <summary>
- /// No permissions, all can read/write
- /// </summary>
- None,
- /// <summary>
- /// Only person in to or from fields
- /// </summary>
- Personal,
- /// <summary>
- /// admin can read/write
- /// </summary>
- Admin
- }
-
- #endregion Enumerations
-
- public class AnnounceBoard : Board
- {
- #region Properties
-
- public override string Description
- {
- get { return "Board for announcements from administrators."; }
- }
-
- public override int Id
- {
- get { return 1; }
- }
-
- public override string Name
- {
- get { return "Announce"; }
- }
-
- public override BoardPermissions ReadPermission
- {
- get { return BoardPermissions.None; }
- }
-
- public override BoardPermissions WritePermission
- {
- get { return BoardPermissions.Admin; }
- }
-
- #endregion Properties
- }
-
- /// <summary>
- /// Implementation of board.
- /// </summary>
- public abstract class Board : IEntity<int>, IPersistent
- {
- #region Fields
-
- public static readonly HashSet<Board> List = new HashSet<Board>();
-
- #endregion Fields
-
- #region Constructors
-
- static Board()
- {
- var assm = Assembly.GetExecutingAssembly();
-
- using (var conn = ArtheaHelper.NewConnection())
- {
- foreach (var t in assm.GetTypes())
- {
- if (t.IsSubclassOf(typeof(Board)))
- {
- var b = (Board)Activator.CreateInstance(t);
- b.Load(conn);
- List.Add(b);
- }
- }
- }
- }
-
- /// <summary>
- /// Initializes a new instance of the <see cref="Board"/> class.
- /// </summary>
- public Board()
- {
- Notes = new ObservableCollection<Note>();
- Notes.CollectionChanged +=
ArtheaHelper.CollectionChangedHandler<Note>((n, a) =>
- {
- n.Board = a ? this : null;
- });
- }
-
- #endregion Constructors
-
- #region Properties
-
- public abstract string Description
- {
- get;
- }
-
- public abstract int Id
- {
- get;
- }
-
- public abstract string Name
- {
- get;
- }
-
- public ObservableCollection<Note> Notes
- {
- get; set;
- }
-
- public abstract BoardPermissions ReadPermission
- {
- get;
- }
-
- public abstract BoardPermissions WritePermission
- {
- get;
- }
-
- #endregion Properties
-
- #region Methods
-
- public static Note FindNote(long id)
- {
- foreach (var b in List)
- {
- var n = b.Notes.SingleOrDefault(x => x.Id == id);
-
- if (n != null) return n;
- }
- return null;
- }
-
- public static Board Lookup(int id)
- {
- return List.FirstOrDefault(x => x.Id == id);
- }
-
- /// <summary>
- /// Returns the number of unread notes for a player on this board.
- /// </summary>
- /// <param name="player">The player.</param>
- /// <returns>the number of unread notes</returns>
- public int CountUnreadNotes(Player player)
- {
- if ((ReadPermission & BoardPermissions.Admin) != 0 &&
(player.Account.Flags.HasFlag(AccountFlag.Admin)))
- return 0;
-
- int count = 0;
-
- foreach (Note n in Notes)
- {
- if (player.HasReadNote(n) ||
- !NoteReadableBy(n, player))
- {
- continue;
- }
-
- ++count;
- }
-
- return count;
- }
-
- public bool Delete(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("delete_board");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return cmd.ExecuteNonQuery() == 1;
- }
-
- /// <summary>
- /// Gets the next unread.
- /// </summary>
- /// <param name="player">The player.</param>
- /// <returns></returns>
- public Note GetNextUnreadNote(Player player)
- {
- if ((ReadPermission & BoardPermissions.Admin) != 0
&& !player.Account.Flags.HasFlag(AccountFlag.Admin))
- return null;
-
- foreach (Note n in Notes)
- {
- if (player.HasReadNote(n) ||
- !NoteReadableBy(n, player))
- {
- continue;
- }
-
- return n;
- }
-
- return null;
- }
-
- public bool Load(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("read_board");
- cmd.AddParameter("@id", DbType.Int32, Id);
-
- return this.Load(cmd);
- }
-
- public int MapRow(IDataRecord reader)
- {
- return 0;
- }
-
- public bool Save(IDbConnection conn)
- {
- var cmd = conn.CreateCommand("save_board");
-
- cmd.AddParameter("@id", DbType.Int32, Id);
- cmd.AddParameter("@name", DbType.String, Name);
- cmd.AddParameter("@descr", DbType.String, Description);
- cmd.AddParameter("@read_perm", DbType.String,
ReadPermission.ToString());
- cmd.AddParameter("@write_perm", DbType.String,
WritePermission.ToString());
-
- return cmd.ExecuteNonQuery() > 0;
- }
-
- /// <summary>
- /// Shows the note list to.
- /// </summary>
- /// <param name="player">The player.</param>
- public void ShowNoteListTo(Player player)
- {
- StringCollection columns = new StringCollection();
-
- var count = 0;
-
- foreach(var note in Notes)
- {
- if (!NoteReadableBy(note, player))
- continue;
-
- columns.Add(string.Format("{0}{1,-2}> {2} ({3})",
-
player.HasReadNote(note) ? "~R*~x" : " ",
- (count + 1), note.Subject,
note.From));
- count++;
- }
-
- Columns.Show(player, 2, columns);
- }
-
- /// <summary>
- /// Returns a <see cref="T:System.String"></see> that represents
the current <see cref="T:System.Object"></see>.
- /// </summary>
- /// <returns>
- /// A <see cref="T:System.String"></see> that represents the
current <see cref="T:System.Object"></see>.
- /// </returns>
- public override string ToString()
- {
- return Name;
- }
-
- /// <summary>
- /// Determines whether a specific note can be read on this board.
- /// </summary>
- /// <param name="note">The note.</param>
- /// <param name="player">The player.</param>
- /// <returns>
- /// <c>true</c> if this the specified note can be read on this
board; otherwise, <c>false</c>.
- /// </returns>
- private bool NoteReadableBy(Note note, Character player)
- {
- return ((ReadPermission & BoardPermissions.Personal) == 0 ||
- note.From == player.Name ||
- note.To.Contains(player.Name));
- }
-
- #endregion Methods
- }
-}
=======================================
--- /trunk/ArtheaEngine/ArtheaEngine.csproj Wed Apr 20 15:25:46 2011
+++ /trunk/ArtheaEngine/ArtheaEngine.csproj Fri Apr 22 09:57:31 2011
@@ -91,7 +91,7 @@
<Compile Include="Dice.cs" />
<Compile Include="IPersistent.cs" />
<Compile Include="Extensions.cs" />
- <Compile Include="Model\Board.cs" />
+ <Compile Include="Model\Forum.cs" />
<Compile Include="Model\Note.cs" />
<Compile Include="Model\Ability.cs" />
<Compile Include="Model\Affect.cs" />
=======================================
--- /trunk/ArtheaEngine/Model/Note.cs Tue Apr 19 15:57:05 2011
+++ /trunk/ArtheaEngine/Model/Note.cs Fri Apr 22 09:57:31 2011
@@ -48,7 +48,7 @@

#region Properties

- public Board Board
+ public Forum Forum
{
get; set;
}
@@ -97,14 +97,14 @@

#region Methods

- public static void ReadAll(Board board)
+ public static void ReadAll(Forum Forum)
{
using (var conn = ArtheaHelper.NewConnection())
{
try
{
- var cmd = conn.CreateCommand("select_board_notes");
- cmd.AddParameter("@id", DbType.Int32, board.Id);
+ var cmd = conn.CreateCommand("select_forum_notes");
+ cmd.AddParameter("@id", DbType.Int32, Forum.Id);

var reader = cmd.ExecuteReader();

@@ -114,10 +114,10 @@

note.MapRow(reader);

- board.Notes.Add(note);
+ Forum.Notes.Add(note);
}

- foreach (var note in board.Notes)
+ foreach (var note in Forum.Notes)
{
note.ReadReplies(conn);
}
@@ -133,7 +133,7 @@
{
var cmd = conn.CreateCommand("delete_note");
cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@board", DbType.Int32, Board.Id);
+ cmd.AddParameter("@Forum", DbType.Int32, Forum.Id);

return cmd.ExecuteNonQuery() == 1;
}
@@ -143,7 +143,7 @@
var cmd = conn.CreateCommand("read_note");

cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@board", DbType.Int32, Board.Id);
+ cmd.AddParameter("@Forum", DbType.Int32, Forum.Id);

var reader = cmd.ExecuteReader();

@@ -153,14 +153,14 @@

if (!reader.IsDBNull(i))
{
- var board = Board.Lookup(reader.GetInt32(i));
- if (board != null)
- board.Notes.Add(this);
+ var forum = Forum.Lookup(reader.GetInt32(i));
+ if (forum != null)
+ forum.Notes.Add(this);
}
i++;

if (!reader.IsDBNull(i))
- Original = Board.FindNote(reader.GetInt64(i));
+ Original = Forum.FindNote(reader.GetInt64(i));
return true;
}

@@ -187,10 +187,10 @@
cmd.AddParameter("@from", DbType.String, From);
cmd.AddParameter("@subject", DbType.String, Subject);
cmd.AddParameter("@when", DbType.DateTime, When);
- if (Board != null)
- cmd.AddParameter("@board", DbType.Int32, Board.Id);
+ if (Forum != null)
+ cmd.AddParameter("@forum", DbType.Int32, Forum.Id);
else
- cmd.AddParameter("@board", DbType.Int32, DBNull.Value);
+ cmd.AddParameter("@forum", DbType.Int32, DBNull.Value);
if (Original != null)
cmd.AddParameter("@original", DbType.Int64, Original.Id);
else
@@ -208,7 +208,7 @@
{
var cmd = conn.CreateCommand("select_note_replies");
cmd.AddParameter("@id", DbType.Int64, Id);
- cmd.AddParameter("@board", DbType.Int32, Board.Id);
+ cmd.AddParameter("@forum", DbType.Int32, Forum.Id);

var reader = cmd.ExecuteReader();

@@ -231,6 +231,22 @@
reply.ReadReplies(conn);
}
}
+
+
+ /// <summary>
+ /// Determines whether a specific note can be read on this Forum.
+ /// </summary>
+ /// <param name="note">The note.</param>
+ /// <param name="player">The player.</param>
+ /// <returns>
+ /// <c>true</c> if this the specified note can be read on this
Forum; otherwise, <c>false</c>.
+ /// </returns>
+ public bool ReadableBy(Character player)
+ {
+ return
(Forum.ReadPermission.HasFlag(ForumPermissions.Personal) ||
+ From == player.Name ||
+ To.Contains(player.Name));
+ }

#endregion Methods
}
=======================================
--- /trunk/ArtheaEngine/Model/Player.cs Thu Apr 21 17:19:32 2011
+++ /trunk/ArtheaEngine/Model/Player.cs Fri Apr 22 09:57:31 2011
@@ -153,10 +153,10 @@

public bool HasReadNote(Note note)
{
- if (!LastNote.ContainsKey(note.Board.Id))
+ if (!LastNote.ContainsKey(note.Forum.Id))
return false;

- return note.When < LastNote[note.Board.Id];
+ return note.When < LastNote[note.Forum.Id];
}

public override bool Load(IDbConnection conn)
=======================================
--- /trunk/ArtheaServer/ArtheaServer.csproj Wed Apr 20 15:25:46 2011
+++ /trunk/ArtheaServer/ArtheaServer.csproj Fri Apr 22 09:57:31 2011
@@ -74,6 +74,7 @@
<Compile Include="Commands\Command.cs" />
<Compile Include="Commands\CommandsCommand.cs" />
<Compile Include="Commands\EditCommand.cs" />
+ <Compile Include="Commands\ForumCommand.cs" />
<Compile Include="Commands\KillCommand.cs" />
<Compile Include="Commands\LookCommand.cs" />
<Compile Include="Commands\QuitCommand.cs" />
Reply all
Reply to author
Forward
0 new messages