github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/client.html (about) 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4 <meta charset="UTF-8"> 5 <title>Title</title> 6 <script type="text/javascript"> 7 var ws = null 8 // 发送 Hello 消息 9 sendJSONObject = function (obj) { 10 if (ws && ws.readyState == WebSocket.OPEN) { 11 ws.send(JSON.stringify(obj)) 12 } 13 return Object.keys(obj) 14 } 15 16 connectLocal = function () { 17 let wsaddr = "ws://" + document.getElementById("local_wsaddr").value 18 initWebSocket(wsaddr) 19 } 20 21 connectLocal2 = function () { 22 let wsaddr = "ws://" + document.getElementById("local_wsaddr2").value 23 initWebSocket(wsaddr) 24 } 25 26 connectRemote = function () { 27 let wsaddr = "ws://" + document.getElementById("remote_wsaddr").value 28 initWebSocket(wsaddr) 29 } 30 31 connectRemote2 = function () { 32 let wsaddr = "ws://" + document.getElementById("remote_wsaddr2").value 33 initWebSocket(wsaddr) 34 } 35 36 initWebSocket = function (wsaddr) { 37 if (ws != null) { 38 return 39 } 40 ws = new WebSocket(wsaddr) 41 ws.onopen = function () { 42 document.getElementById("connect").style.display = "none" 43 document.getElementById("login").style.display = "" 44 } 45 46 ws.onmessage = function (e) { 47 var reader = new FileReader(); 48 reader.readAsText(e.data) 49 reader.onload = function () { 50 // console.log(this.result) 51 var result = JSON.parse(this.result) 52 if (result.S2C_Login) { 53 console.log("S2C_Login: ", result.S2C_Login) 54 } else if (result.S2C_Heartbeat) { 55 sendJSONObject({C2S_Heartbeat: {}}) 56 } else if (result.S2C_ActionMahjongDiscard) { 57 console.log("S2C_ActionMahjongDiscard: ", result.S2C_ActionMahjongDiscard) 58 } else if (result.S2C_TotalResults) { 59 console.log("S2C_TotalResults: ", result.S2C_TotalResults) 60 } else if (result.S2C_RoundResults) { 61 console.log("S2C_RoundResults: ", result.S2C_RoundResults) 62 } else if (result.S2C_TransferChips) { 63 console.log("S2C_TransferChips: ", result.S2C_TransferChips) 64 } else { 65 console.log(result) 66 } 67 } 68 } 69 70 ws.onerror = function () { 71 alert("连接 " + wsaddr + " 失败!") 72 } 73 74 ws.onclose = function () { 75 ws = null 76 document.getElementById("connect").style.display = "" 77 document.getElementById("login").style.display = "none" 78 } 79 } 80 81 wechatLogin = function () { 82 let unionid = document.getElementById("unionid").value 83 var obj = { 84 C2S_WeChatLogin: { 85 // Nickname: "我是谁", 86 // Headimgurl: "http://wx.qlogo.cn/mmopen/Po9mkm3Z42tolYpxUVpY6mvCmqalibOpcJ2jG3Qza5qgtibO1NLFNUF7icwCibxPicbGmkoiciaqKEIdvvveIBfEQqal8vkiavHIeqFT/0", 87 // Sex: 1, 88 Unionid: unionid 89 } 90 } 91 sendJSONObject(obj) 92 } 93 94 usernamePasswordLogin = function () { 95 let username = document.getElementById("username").value 96 let password = document.getElementById("password").value 97 var obj = { 98 C2S_UsernamePasswordLogin: { 99 Username: username, 100 Password: password, 101 } 102 } 103 sendJSONObject(obj) 104 } 105 106 setUsernamePassword = function () { 107 let username = document.getElementById("username").value 108 let password = document.getElementById("password").value 109 var obj = { 110 C2S_SetUsernamePassword: { 111 Username: username, 112 Password: password, 113 } 114 } 115 sendJSONObject(obj) 116 } 117 118 setRole = function (role) { 119 let accountid = document.getElementById("accountid").value 120 var obj = { 121 C2S_SetUserRole: { 122 AccountID: parseInt(accountid), 123 Role: role, 124 } 125 } 126 sendJSONObject(obj) 127 } 128 129 transferChips = function () { 130 let accountid = document.getElementById("accountid").value 131 let chips = document.getElementById("chips").value 132 var obj = { 133 C2S_TransferChips: { 134 AccountID: parseInt(accountid), 135 Chips: parseInt(chips), 136 } 137 } 138 sendJSONObject(obj) 139 } 140 141 discard = function () { 142 let tile = document.getElementById("tile").value 143 var obj = { 144 C2S_MahjongDiscard: { 145 Tile: parseInt(tile), 146 } 147 } 148 sendJSONObject(obj) 149 } 150 151 setAndroidVersion = function () { 152 let v = document.getElementById("androidversion").value 153 var obj = { 154 C2S_SetLandlordConfig: { 155 AndroidVersion: parseInt(v), 156 } 157 } 158 sendJSONObject(obj) 159 } 160 161 setIOSVersion = function () { 162 let v = document.getElementById("iosversion").value 163 var obj = { 164 C2S_SetLandlordConfig: { 165 IOSVersion: parseInt(v), 166 } 167 } 168 sendJSONObject(obj) 169 } 170 171 setWeChatNumber = function () { 172 let v = document.getElementById("wechatnumber").value 173 var obj = { 174 C2S_SetLandlordConfig: { 175 WeChatNumber: v, 176 } 177 } 178 sendJSONObject(obj) 179 } 180 181 setNotice = function () { 182 let v = document.getElementById("notice").value 183 var obj = { 184 C2S_SetLandlordConfig: { 185 Notice: v, 186 } 187 } 188 sendJSONObject(obj) 189 } 190 191 setRadio = function () { 192 let v = document.getElementById("radio").value 193 var obj = { 194 C2S_SetLandlordConfig: { 195 Radio: v, 196 } 197 } 198 sendJSONObject(obj) 199 } 200 201 startMatching = function () { 202 var obj = { 203 C2S_StartLandlordMatching: {} 204 } 205 sendJSONObject(obj) 206 } 207 208 setSystemOn = function (on) { 209 var obj = { 210 C2S_SetSystemOn: { 211 On: on, 212 } 213 } 214 sendJSONObject(obj) 215 } 216 217 getTotalResult = function () { 218 var obj = { 219 C2S_GetTotalResults: {} 220 } 221 sendJSONObject(obj) 222 } 223 224 getRoundResult = function () { 225 let id = document.getElementById("totalreultid").value 226 var obj = { 227 C2S_GetRoundResults: { 228 TotalResultID: parseInt(id), 229 } 230 } 231 sendJSONObject(obj) 232 } 233 234 setRobotChips = function () { 235 let id = document.getElementById("robotChip").value 236 var obj = { 237 C2S_SetRobotData: { 238 Chips: parseInt(id) 239 } 240 } 241 sendJSONObject(obj) 242 } 243 244 getCircleLoginCode = function () { 245 var obj = { 246 C2S_GetCircleLoginCode: { 247 248 } 249 } 250 sendJSONObject(obj) 251 } 252 </script> 253 </head> 254 <body> 255 <div id="connect"> 256 ws://<input id="local_wsaddr" type="text" value="192.168.1.168:3658"> 257 <button onclick="connectLocal()">连接本地测试</button> 258 <br> 259 ws://<input id="local_wsaddr2" type="text" value="192.168.1.141:3658"> 260 <button onclick="connectLocal2()">连接本地测试2</button> 261 <br> 262 ws://<input id="remote_wsaddr" type="text" value="139.199.180.94:3658"> 263 <button onclick="connectRemote()">连接远程测试</button> 264 <br> 265 ws://<input id="remote_wsaddr2" value="czddz.shenzhouxing.com:3658"> 266 <button onclick="connectRemote2()">连接远程正式</button> 267 </div> 268 <div id="login" style="display: none"> 269 Union ID:<input id="unionid" value="o8c-nt6tO8aIBNPoxvXOQTVJUxY0"> 270 <br> 271 <button onclick="wechatLogin()">微信登录</button> 272 <br> 273 账号:<input id="username" type="text" value="我是谁"> 274 密码:<input id="password" type="text" value="123456"> 275 <br> 276 <button onclick="usernamePasswordLogin()">账密登录</button> 277 <button onclick="setUsernamePassword()">设置账密</button> 278 <br> 279 Account ID:<input id="accountid" value="79362"> 280 <br> 281 <button onclick="setRole(3)">设置为管理员</button> 282 <button onclick="setRole(2)">设置为代理</button> 283 <button onclick="setRole(1)">设置为玩家</button> 284 <button onclick="setRole(-1)">拉黑</button> 285 <br> 286 筹码:<input id="chips" value="1"> 287 <button onclick="transferChips()">转筹码</button> 288 <br> 289 出牌:<input id="tile" value="0"> 290 <button onclick="discard()">出牌</button> 291 <br> 292 安卓新版本:<input id="androidversion" value="1"> 293 <button onclick="setAndroidVersion()">设置</button> 294 <br> 295 iOS 新版本:<input id="iosversion" value="1"> 296 <button onclick="setIOSVersion()">设置</button> 297 <br> 298 客服微信号:<input id="wechatnumber" value="zhongyusw01"> 299 <button onclick="setWeChatNumber()">设置</button> 300 <br> 301 公告:<input id="notice" value="诚招代理,咨询详情请加微信:zhongyusw01"> 302 <button onclick="setNotice()">设置</button> 303 <br> 304 广播:<input id="radio" value="诚招代理,咨询详情请加微信:zhongyusw01"> 305 <button onclick="setRadio()">设置</button> 306 <br> 307 <button onclick="startMatching()">练习场</button> 308 <br> 309 系统开关: 310 <button onclick="setSystemOn(true)">开</button> 311 <button onclick="setSystemOn(false)">关</button> 312 <br> 313 <button onclick="getTotalResult()">总成绩</button> 314 <br> 315 总成绩 ID:<input id="totalreultid" value="1"> 316 <button onclick="getRoundResult()">单局成绩</button> 317 <br> 318 金币: <input id="robotChip" value="1"> 319 <button onclick="setRobotChips()">机器人加金币</button> 320 <br> 321 圈圈授权: 322 <button onclick="getCircleLoginCode()">授权</button> 323 <br> 324 </div> 325 </body> 326 </html>