|
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Linq;
using System.Collections.Generic;
using CChess;
public partial class CChessPlayer
{
/// <summary>
/// It's the number of seconds that can pass without recieving a message.
/// After that, the user is offline.
/// </summary>
public const int LEGAL_INACTIVITY_SECONDS = 30;
public bool IsOnline()
{
CChessDataContext cdc = new CChessDataContext();
int players_count = (from p in cdc.CChessPlayers
where p.player_id == this.player_id &&
UnixDate.GetCurrentUnixTimestamp() - p.last_activity < 30
select new { ID = p.player_id }).Count();
return (players_count > 0);
}
public bool IsInAGame()
{
CChessDataContext cdc = new CChessDataContext();
int games_count = cdc.CChessGamesPlayers.Count(p => ((p.player_id == player_id) && (p.CChessGame.game_state != (byte)CChessGameStates.Finished)));
return (games_count > 0);
}
partial void OnValidate(ChangeAction action)
{
if (player_nick == String.Empty)
{
throw new Exception("The nickname is empty.");
}
CChessDataContext cdc = new CChessDataContext();
List<CChessPlayer> is_unique_player = (from players in cdc.GetOnlinePlayers(CChessPlayer.LEGAL_INACTIVITY_SECONDS, UnixDate.GetCurrentUnixTimestamp())
where players.player_nick == player_nick
select new CChessPlayer
{
player_id = players.player_id
}).ToList();
if (is_unique_player.Count > 0)
{
throw new Exception("This username is currently being used by another player, please choose another one.");
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
My name is Julian, I was born in Argentina, but I've been living in Israel for 6 years already. I'm a high school student in my last year, I study computer science, physics and math.
Other than programming, I really enjoy watching anime and reading manga.