/// <summary> /// Creates a command for inserting message /// </summary> /// <param name="message"></param> /// <param name="source"></param> /// <param name="stacktrase"></param> /// <param name="onServer"></param> /// <returns></returns> private static SqlCommand CreateInsertMessage(string message, int clientID, eSources source, eMessageTypes type, string stackTrace, DateTime dateGenerated) { const string sql = "spInsertMessage"; return(MSSQL.CreateCommand(ConnectionString, sql, CommandType.StoredProcedure, new SqlParameter("@ClientID", clientID), new SqlParameter("@Message", message), new SqlParameter("@Type", Convert.ToInt32(type)), new SqlParameter("@SourceID", Convert.ToInt32(source)), new SqlParameter("@StackTrace", stackTrace), new SqlParameter("@DateGenerated", dateGenerated))); }
public static MessageBase FromByteArray(byte[] b) { MemoryStream memoryStream = new MemoryStream(b); BinaryReader binaryReader = new BinaryReader(memoryStream); int size = binaryReader.ReadInt32(); eMessageTypes eMessageType = (eMessageTypes)binaryReader.ReadInt32(); MessageBase m; switch (eMessageType) { case eMessageTypes.ConnnectMessage: m = new ConnectMessage(); break; case eMessageTypes.DisconnectMessage: m = new DisconnectMessage(); break; case eMessageTypes.ReadyMessage: m = new ReadyMessage(); break; case eMessageTypes.StartGameMessage: m = new StartGameMessage(); break; case eMessageTypes.StopGameMessage: m = new StopGameMessage(); break; case eMessageTypes.ChatMessage: m = new ChatMessage(); break; case eMessageTypes.HeartbeatMessage: m = new HeartbeatMessage(); break; case eMessageTypes.GameStateMessage: m = new GameStateMessage(); break; case eMessageTypes.GameInputMessage: m = new GameInputMessage(); break; case eMessageTypes.EndTurnMessage: m = new EndTurnMessage(); break; case eMessageTypes.GameSettingsMessage: m = new GameSettingsMessage(); break; case eMessageTypes.ClientInformationMessage: m = new ClientInformationMessage(); break; case eMessageTypes.PlayerRenameMessage: m = new PlayerRenameMessage(); break; case eMessageTypes.RoomCreationMessage: m = new RoomCreationMessage(); break; case eMessageTypes.RoomListUpdateMessage: m = new RoomListUpdateMessage(); break; case eMessageTypes.RoomJoinMessage: m = new RoomJoinMessage(); break; case eMessageTypes.RoomInformationMessage: m = new RoomInformationMessage(); break; case eMessageTypes.MapSendMessage: m = new MapSendMessage(); break; case eMessageTypes.RoomLobbyMessage: m = new RoomLobbyMessage(); break; case eMessageTypes.SurrenderMessage: m = new SurrenderMessage(); break; default: //TODO: DONT LET THE SERVER CRASH (Default Chat Massage) throw new ArgumentOutOfRangeException(); } m.Read(binaryReader); return(m); }
/// <summary> /// Insert message to the database. Do not fire errors. /// </summary> /// <param name="message"></param> /// <param name="source"></param> /// <param name="stacktrase"></param> /// <param name="onServer"></param> public static void InsertMessageAsync(string message, int clientID, eSources source, eMessageTypes type, string stackTrase, DateTime dateGenerated) { // Do not refire errors SQLWorker.Default.Add(CreateInsertMessage(message, clientID, source, type, stackTrase, dateGenerated), //No Errors! PTFUtils.EmptyThreadExceptionEventHandler()); }
/// <summary> /// Insert message to the database. Do not fire errors. /// </summary> /// <param name="message"></param> /// <param name="source"></param> /// <param name="stacktrase"></param> /// <param name="onServer"></param> public static void InsertMessage(string message, int clientID, eSources source, eMessageTypes type, string stackTrase, DateTime dateGenerated) { // Do not refire errors SQL.ExecuteNonQuery(CreateInsertMessage(message, clientID, source, type, stackTrase, dateGenerated)); }
/// <summary> /// Creates command for inserting message to the client database /// </summary> /// <param name="message"></param> /// <param name="source"></param> /// <param name="stacktrase"></param> /// <param name="onServer"></param> /// <returns></returns> private static SqlCommand CreateInsertMessage(string message, eSources source, eMessageTypes type, string stackTrase) { const string sql = "INSERT INTO MESSAGES(Message, Source, Type, StackTrace, DateInserted) VALUES " + "(@Message, @Source, @Type, @StackTrace, @DateInserted);"; return(MSSQL.CreateCommand(ConnectionString, sql, new SqlParameter("@Message", message.Top(1024)), new SqlParameter("@Source", Convert.ToInt32(source)), new SqlParameter("@Type", Convert.ToInt32(type)), new SqlParameter("@StackTrace", stackTrase.Top(2028)), new SqlParameter("@DateInserted", DateTime.Now))); }
/// <summary> /// Inserts message to the client database asynchronously /// </summary> /// <param name="message"></param> /// <param name="source"></param> /// <param name="type"></param> /// <param name="stacktrase"></param> public static void InsertMessageAsync(string message, eSources source, eMessageTypes type, string stacktrase) { // Do not refire errors SQLWorker.Default.Add(CreateInsertMessage(message, source, type, stacktrase)); }
/// <summary> /// Inserts message to the client database /// </summary> /// <param name="message"></param> /// <param name="source"></param> /// <param name="type"></param> /// <param name="stacktrase"></param> public static void InsertMessage(string message, eSources source, eMessageTypes type, string stacktrase) { SQL.ExecuteNonQuery(CreateInsertMessage(message, source, type, stacktrase)); }