gauthd
 
Loading...
Searching...
No Matches
D:/pwsrc2.0/docs/gauthd/getaddcashsn.hrp
Go to the documentation of this file.
1/**
2 * @file GetAddCashSN.hpp
3 * @brief Заголовочный файл для обработки запросов генерации серийных номеров пополнения баланса
4 */
5
6#ifndef __GNET_GETADDCASHSN_HPP
7#define __GNET_GETADDCASHSN_HPP
8
9#include "rpcdefs.h"
10#include "callid.hxx"
11#include "state.hxx"
12#include "getaddcashsnarg"
13#include "getaddcashsnres"
14#include "gmysqlclient.hpp"
15#include "gauthserver.hpp"
16#include "addcash.hpp"
17
18namespace GNET
19{
20
21/**
22 * @class GetAddCashSN
23 * @brief RPC-класс для обработки запросов генерации серийных номеров пополнения
24 *
25 * Наследует функциональность ProxyRpc и взаимодействует с базой данных через GMysqlClient,
26 * а также отправляет ответы через GAuthServer.
27 */
28class GetAddCashSN : public ProxyRpc
29{
30#define RPC_BASECLASS ProxyRpc
31 #include "getaddcashsn" ///< Включение сгенерированного RPC-кода
32#undef RPC_BASECLASS
33
34private:
35 /**
36 * @brief Отправляет информацию о неудачной операции в БД
37 * @param userid Идентификатор пользователя
38 * @param status Статус ошибки (0 - ошибка доставки, 1 - ошибка обработки)
39 * @note Удаляет соответствующую запись из таблицы ошибок
40 */
41 void SendFailCash(int userid, int status)
42 {
43 printf("GetAddCashSN::SendFailCash: userid = %d \n", userid);
44 GMysqlClient *db = GMysqlClient::GetInstance();
45 int idx = db->GetCashUser(userid);
46 char * creatime = db->GetCashCreaTime(idx);
47 db->DeleteErrorRow(status, userid, creatime);
48 db->DelCashUser(idx);
49 }
50
51public:
52 /**
53 * @brief Обрабатывает доставку RPC-запроса
54 * @param proxy_sid Идентификатор сессии прокси
55 * @param osArg Входные данные в виде OctetsStream
56 * @return true если запрос успешно отправлен, false в случае ошибки
57 * @note При ошибке отправляет спонсору результат ERR_DELIVER_SEND
58 */
59 bool Delivery(Manager::Session::ID proxy_sid, const OctetsStream& osArg)
60 {
61 if( GAuthServer::GetInstance()->Send(proxy_sid, *this ) )
62 return true;
63
64 GetAddCashSNArg arg;
65 osArg >> arg;
66 SetResult(GetAddCashSNRes(ERR_DELIVER_SEND));
67 SendToSponsor();
68 SendFailCash(arg.userid, 0);
69 return false;
70 }
71
72 /**
73 * @brief Постобработка результатов RPC-запроса
74 * @param proxy_sid Идентификатор сессии прокси
75 * @param osArg Входные аргументы
76 * @param osRes Результаты выполнения
77 * @note Обновляет статус операции в БД, инициирует пополнение баланса при успехе
78 */
79 void PostProcess(Manager::Session::ID proxy_sid, const OctetsStream& osArg, const OctetsStream& osRes)
80 {
81 GetAddCashSNArg arg;
82 osArg >> arg;
83
84 GetAddCashSNRes res;
85 osRes >> res;
86
87 GMysqlClient *db = GMysqlClient::GetInstance();
88 if(res.retcode != 0) {
89 SendFailCash(res.userid, 1);
90 return;
91 }
92
93 int idx = db->GetCashUser(res.userid);
94 int cash = db->GetCashCash(idx);
95 char * creatime = db->GetCashCreaTime(idx);
96
97 if(!creatime || !cash) {
98 SendFailCash(res.userid, 1);
99 return;
100 }
101
102 int result = db->SetUseCashNow(1, res.sn, res.userid, creatime);
103 if( result )
104 {
105 AddCash Cash = AddCash(res.userid, res.zoneid, res.sn, cash );
106 GAuthServer::GetInstance()->Send(proxy_sid, &Cash);
107 }
108 SetResult( &res );
109 }
110
111 /**
112 * @brief Обработчик таймаута запроса
113 * @note В текущей реализации не выполняет действий (закомментирован)
114 */
115 void OnTimeout( )
116 {
117 //SendFailCash();
118 }
119};
120
121};
122#endif