hzr
2024-08-05 0a2757042cb3bc30831e7dde93cfb3aee2280d47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<?php
include_once '/Common/CommFunc.php';
include_once '/Common/Logging.php';
include_once "/db/DBOper.php";
 
header("Content-type: text/html; charset=utf-8");
 
\Logging\CreateLogging("eventreport.eventreport.php");
 
// 2022-05-09T19:17:47    DEBUG           Version=
// 2022-05-09T19:17:47    DEBUG           DeviceFlag=
// 2022-05-09T19:17:47    DEBUG           SessionID=c8b996d5ffdc71139b1d4bc22874b2f8
// 2022-05-09T19:17:47    DEBUG           EventID=1100
// 2022-05-09T19:17:47    DEBUG           ProductID=xbqy
// 2022-05-09T19:17:47    DEBUG           OperatorID=test
// 2022-05-09T19:17:47    DEBUG           RegionName=s86
// 2022-05-09T19:17:47    DEBUG           Time=2022-05-09 19:17:47
// 2022-05-09T19:17:47    DEBUG           AccountID=yn1233
// 2022-05-09T19:17:47    DEBUG           PlayerID=280104
// 2022-05-09T19:17:47    DEBUG           RoleID=ĐạmDiệuHải
// 2022-05-09T19:17:47    DEBUG           Level=400
// 2022-05-09T19:17:47    DEBUG           Job=1
// 2022-05-09T19:17:47    DEBUG           IP=192.168.1.1
 
$EventID = $_GET["EventID"];
$GameName = $_GET["ProductID"];
$Channel = $_GET["OperatorID"];
$RegionName = $_GET["RegionName"];
$Time = $_GET["Time"];
 
\Logging\LogInfo(" _GET:" . print_r($_GET, true));
 
if (
    !$EventID || !$Channel || !$RegionName || !$Time || !$GameName || $GameName != \CommFunc\GetGameName()
) {
    Response(1000, "param error");
    exit;
}
 
$ok = false;
switch ($EventID) {
    case 1100:
        $ok = EventReport_UpdateRole("Login");
        break;
 
    case 1101:
        $ok = EventReport_UpdateRole("Logoff");
        break;
 
    case 9001:
        $Flag = $_GET["Flag"];
        // 流失模型中,Flag 1000 为首登成功
        if ($Flag == 1000) {
            $ok = EventReport_CreateRole();
        }
        break;
 
    default:
        Response(1001, "unknown eventID -> " . $EventID);
        exit;
}
if ($ok) {
    Response();
}
exit;
 
function Response($errorcode = 0, $errormsg = "ok")
{
    $ret = array("errorcode" => $errorcode, "errormsg" => $errormsg);
    if ($errorcode != 0) {
        \Logging\LogError($errormsg . " _GET:" . print_r($_GET, true) . " ret:" . print_r($ret, true));
    }
    echo \CommFunc\MyJson_encode($ret);
}
 
function EventReport_UpdateRole($eventType)
{
    global $Channel, $RegionName, $Time;
 
    $AccountID = $_GET["AccountID"];
    $PlayerID = intval($_GET["PlayerID"]);
    $PlayerName = $_GET["RoleID"];
    $LV = intval($_GET["Level"]);
    $Job = intval($_GET["Job"]);
    $IP = $_GET["IP"];
    $FamilyName = array_key_exists("FamilyName", $_GET) ? $_GET["FamilyName"] : "";
    $FightPower = $_GET["FightPower"];
    settype($FightPower, "float");
    $AllCoinTotal = intval($_GET["AllCoinTotal"]);
 
    if (!$AccountID || !$PlayerID || !$PlayerName || !$LV || !$Job || !$IP) {
        Response(1003, "role param error");
        return;
    }
 
    $find = array("Channel" => $Channel, "AccountID" => $AccountID);
    // 只找对应服的数据更新即可
    if (!\DBOper\FindOne("GameRoles", $find, $findData, array($RegionName => 1))) {
        Response(2000, "db find error");
        return;
    }
    $newAccount = false;
    if (!isset($findData)) {
        $newAccount = true;
    }
    \Logging\LogInfo("newAccount:" . $newAccount . " findData:" . print_r($findData, true));
 
    $roleInfo = array();
    if (isset($findData) && array_key_exists($RegionName, $findData)) {
        $regionRole = $findData[$RegionName];
        // 如果是redis取出来的是json字符串
        if (is_string($regionRole)) {
            $regionRole = json_decode($regionRole, true);
            // \Logging\LogInfo("json_decode regionRole:" . print_r($regionRole, true));
        }
        foreach ($regionRole as $key => $value) {
            $roleInfo[$key] = $value;
        }
    }
 
    $roleInfo["PlayerID"] = $PlayerID;
    $roleInfo["PlayerName"] = $PlayerName;
    $roleInfo["LV"] = $LV;
    $roleInfo["Job"] = $Job;
    $roleInfo["IP"] = $IP;
    $roleInfo["FamilyName"] = $FamilyName;
    $roleInfo["FightPower"] = $FightPower;
    $roleInfo["AllCoinTotal"] = $AllCoinTotal;
    if (array_key_exists("CreateRoleTime", $_GET)) {
        $roleInfo["CreateRoleTime"] = $_GET["CreateRoleTime"];
    }
    if ($eventType == "Login") {
        $roleInfo["LoginTime"] = $Time;
    } elseif ($eventType == "Logoff") {
        $roleInfo["LogoffTime"] = $Time;
    }
 
    if ($newAccount) {
        $insArray = array(
            "Channel" => $Channel,
            "AccountID" => $AccountID,
            "CreateTime" => date("Y-m-d H:i:s"),
            $RegionName => $roleInfo
        );
        if (!\DBOper\Insert("GameRoles", $insArray, $find)) {
            Response(2001, "db Insert error");
            return;
        }
    } else {
        $setRole = array($RegionName => $roleInfo);
        if (!\DBOper\Update("GameRoles", $find, $setRole, true)) {
            Response(2002, "db Update error");
            return;
        }
    }
    return true;
}
 
function EventReport_CreateRole()
{
    global $Channel, $RegionName;
 
    $ServerID = \CommFunc\GetServerIDBySid($RegionName);
    if (!$ServerID) {
        return;
    }
    $find = array("Channel" => $Channel, "ServerID" => $ServerID);
    if (!\DBOper\FindOne("GameServerInfo", $find, $findData, null, false)) {
        Response(2000, "db find error");
        return;
    }
    \Logging\LogInfo(" findData:" . print_r($findData, true));
 
    if (!isset($findData)) {
        $insArray = array(
            "Channel" => $Channel,
            "ServerID" => $ServerID,
            "CreateRoleCount" => 1,
        );
        if (!\DBOper\Insert("GameServerInfo", $insArray, $find)) {
            Response(2001, "db Insert error");
            return;
        }
        \Logging\LogInfo(" insert ServerID:" . $ServerID . " CreateRoleCount:" . 1);
    } else {
        $CreateRoleCount = $findData["CreateRoleCount"] + 1;
        $setArray = array("CreateRoleCount" => $CreateRoleCount);
        if (!\DBOper\Update("GameServerInfo", $find, $setArray)) {
            Response(2002, "db Update error");
            return;
        }
        \Logging\LogInfo(" update ServerID:" . $ServerID . " CreateRoleCount:" . $CreateRoleCount);
    }
    return true;
}