---
# System prepended metadata

title: Guest-ID

---

# Guest-ID

## 編碼

```
2bc43400-dcb2-2c00-b439-75650c113e86
```

編碼規則: 

Key + Hash("Message")

Hash函數以Key為初始值生成，只要是Key不正確Hash結果也不正確。

- 唯一性
- 一次性(不可重複使用)
- 可自我驗證
- 只能在javascript直譯器執行

## 通訊方式

```sequence
JS前端->WebSocketRelay: WebSocket 連入
WebSocketRelay->GS: 協議ID(100) 產生Guest Id + bytecode
GS->WebSocketRelay: 協議ID(100) 送回bytecode
WebSocketRelay->JS前端: 返回協議ID(100)
JS前端->WebSocketRelay: 協議ID(1) token:2bc43400-dcb2-2c00-b439-75650c113e86
WebSocketRelay->GS: 返回協議ID(1) GS驗證
```

## 產生ByteCode

產生bytecode.txt
```
jssanbox -b 5456632
```

## JS呼叫方式

JS前端程式碼範例
``` javascript
b.onRuntimeInitialized = () => {
    const datastr = "getGuestId()";
    const buffer = b.intArrayFromString(datastr);
    const ptr = b.allocate(buffer, 'i8', b.ALLOC_NORMAL);
		
    var byteCodeLen = byteCodeArray.length;
    var byteCode = b.asm.malloc(byteCodeLen);
    b.writeArrayToMemory(new Uint8Array(byteCodeArray), byteCode);
		
    const output = b.asm.malloc(1024); // 1024預設字串緩衝大小
    b._init(byteCode, byteCodeLen);
    b._eval(ptr, 12, output); // 12: 'getGuestId()'字串長度
    b._dispose();
    var guestId = b.UTF8ToString(output)
};
```

## 協議(ID: 100) 新增欄位


| 新增/已存在  | 欄位   | 說明  |
|--- | ----  | ----  |
| 已存在 | GameID  | Game ID |
| 已存在 | ClientIP  | Client IP |
| 已存在 | Token  | Game Token (前端送過來原始token) |
| 新增   | ConnectionId  | 連線編號 (例如: 5171852356103743026) |
| 新增   | CorrelationId  | 請求編號(可能從其他路由過來) |
| 新增   | GuestId | Guest編號小寫GUID格式 (例如: 2bc43400-dcb2-2c00-b439-75650c113e86) |
| 新增   | ByteCode | 無號數陣列 |

* 1. ByteCode與GuestId兩個欄只有在包含"guest"開頭的token才會有資料。

### 1. guest

|  欄位   | 說明  |
| ---  | ----  |
| GameID  | 1 |
| ClientIP  | "10.0.2.2" |
| Token  | "guest" |
| CorrelationId  | "ICYIJ3IQJUW2u-Tph02Rtw" |
| ConnectionId | 5171852356103743026 |
| GuestId | "501cc647-32a6-54f4-481c-a35bc2ab2f3c" |
| ByteCode | [2,72 ...] |


### 2. guest123

|  欄位   | 說明  |
| ---  | ----  |
| GameID  | 1 |
| ClientIP  | "10.0.2.2" |
| Token  | "guest123" |
| CorrelationId  | "ICYIJ3IQJUW2u-Tph02Rtw" |
| ConnectionId | 5171852356103743026 |
| GuestId | "501cc647-32a6-54f4-481c-a35bc2ab2f3c" |
| ByteCode | [2,72 ...] |

### 3. guest:::1000

|  欄位   | 說明  |
| ---  | ----  |
| GameID  | 1 |
| ClientIP  | "10.0.2.2" |
| Token  | "guest:::1000" |
| CorrelationId  | "ICYIJ3IQJUW2u-Tph02Rtw" |
| ConnectionId | 5171852356103743026 |
| GuestId | "501cc647-32a6-54f4-481c-a35bc2ab2f3c" |
| ByteCode | [2,72 ...] |

### 4. guest:THB:Y:9999

|  欄位   | 說明  |
| ---  | ----  |
| GameID  | 1 |
| ClientIP  | "10.0.2.2" |
| Token  | "guest:THB:Y:9999" |
| CorrelationId  | "ICYIJ3IQJUW2u-Tph02Rtw" |
| ConnectionId | 5171852356103743026 |
| GuestId | "501cc647-32a6-54f4-481c-a35bc2ab2f3c" |
| ByteCode | [2,72 ...] |

### 5. edd27ab8a894221a126ecc1e56398403 (Cypress Token)

|  欄位   | 說明  |
| ---  | ----  |
| GameID  | 1 |
| ClientIP  | "10.0.2.2" |
| Token  | "edd27ab8a894221a126ecc1e56398403" |
| CorrelationId  | "pP6cC5M-AU_Db1fL8FtDmA" |
| ConnectionId | 5171852356103743026 |
| GuestId | null |
| ByteCode | null |

### 6. ttedcx

|  欄位   | 說明  |
| ---  | ----  |
| GameID  | 1 |
| ClientIP  | "10.0.2.2" |
| Token  | "ttedcx" |
| CorrelationId  | "pP6cC5M-AU_Db1fL8FtDmA" |
| ConnectionId | 5171852356103743026 |
| GuestId | null |
| ByteCode | null |

### 7. test

|  欄位   | 說明  |
| ---  | ----  |
| GameID  | 1 |
| ClientIP  | "10.0.2.2" |
| Token  | "test" |
| CorrelationId  | "pP6cC5M-AU_Db1fL8FtDmA" |
| ConnectionId | 5171852356103743026 |
| GuestId | null |
| ByteCode | null |


100 回應的內容
```json
~m~10008~m~~j~{"err":200,"res":100,"vals":[1,"[2,72,8,75,69,89,49,8,75,69,89,50,24,77,69,83,83,65,71,69,95,84,69,88,84,14,83,105,112,72,97,115,104,16,116,111,66,117,102,102,101,114,12,103,101,116,73,110,116,24,109,97,107,101,85,105,110,116,56,75,101,121,14,109,97,107,101,75,101,121,24,105,110,115,101,114,116,83,116,114,105,110,103,28,109,97,107,101,85,117,105,100,83,116,114,105,110,103,20,103,101,116,71,117,101,115,116,73,100,42,73,68,52,54,54,49,56,52,56,57,57,50,55,54,53,57,48,50,55,49,57,18,60,115,97,110,100,98,111,120,62,8,95,97,100,100,8,95,120,111,114,10,95,114,111,116,108,14,95,114,111,116,108,51,50,18,95,99,111,109,112,114,101,115,115,16,95,103,101,116,95,105,110,116,8,104,97,115,104,24,115,116,114,105,110,103,95,116,111,95,117,56,2,97,2,98,4,114,108,4,97,50,2,108,2,104,2,110,4,97,108,4,118,48,4,118,49,4,118,50,4,118,51,12,111,102,102,115,101,116,6,107,101,121,2,109,4,107,48,4,107,49,4,109,108,6,109,108,55,6,98,117,102,4,109,112,4,109,105,4,105,99,6,109,105,108,6,115,116,114,10,98,121,116,101,115,2,105,2,106,16,117,110,101,115,99,97,112,101,36,101,110,99,111,100,101,85,82,73,67,111,109,112,111,110,101,110,116,20,99,104,97,114,67,111,100,101,65,116,6,98,105,103,8,115,105,122,101,6,104,101,120,6,108,101,110,4,117,56,16,112,97,114,115,101,73,110,116,10,115,108,105,99,101,8,107,101,121,49,8,107,101,121,50,18,107,101,121,49,65,114,114,97,121,18,107,101,121,50,65,114,114,97,121,12,115,117,98,115,116,114,18,107,101,121,66,117,102,102,101,114,14,109,115,103,72,97,115,104,18,109,115,103,66,117,102,102,101,114,20,117,117,105,100,66,117,102,102,101,114,14,117,117,105,100,83,116,114,2,45,10,117,56,107,101,121,6,114,101,115,14,0,6,0,166,1,0,1,0,1,0,10,180,1,1,168,1,0,0,0,63,226,0,0,0,0,63,227,0,0,0,0,63,228,0,0,0,0,63,229,0,0,0,0,63,230,0,0,0,64,63,231,0,0,0,64,63,232,0,0,0,64,63,233,0,0,0,64,63,234,0,0,0,64,63,235,0,0,0,64,63,236,0,0,0,64,62,226,0,0,0,0,62,227,0,0,0,0,62,228,0,0,0,0,62,229,0,0,0,0,192,3,64,230,0,0,0,0,192,4,64,231,0,0,0,0,192,5,64,232,0,0,0,0,192,6,64,233,0,0,0,0,192,7,64,234,0,0,0,0,192,8,64,235,0,0,0,0,192,9,64,236,0,0,0,0,191,0,57,226,0,0,0,191,1,57,227,0,0,0,4,237,0,0,0,57,228,0,0,0,192,2,238,57,229,0,0,0,197,40,220,3,1,16,0,66,1,0,80,2,38,38,0,10,150,2,0,8,222,1,10,136,1,4,234,109,100,129,10,140,1,4,127,255,82,154,14,67,6,1,0,0,8,0,2,0,8,44,8,222,3,0,0,64,224,3,0,1,64,226,3,0,2,64,228,3,0,3,64,230,3,0,4,64,232,3,0,5,64,234,3,0,6,0,236,3,0,7,64,192,0,201,192,1,202,192,2,203,192,3,204,192,4,195,4,192,5,195,5,192,6,195,6,192,7,195,7,11,194,6,76,245,0,0,0,194,7,76,246,0,0,0,40,220,3,4,7,0,28,140,2,8,38,38,14,67,6,1,222,3,2,2,2,4,0,0,76,4,238,3,0,1,0,240,3,0,1,0,242,3,0,0,0,244,3,0,1,0,209,65,251,0,0,0,210,65,251,0,0,0,157,201,11,209,65,252,0,0,0,210,65,252,0,0,0,157,197,183,155,189,31,162,157,181,162,76,252,0,0,0,197,181,162,76,251,0,0,0,202,209,198,65,252,0,0,0,67,252,0,0,0,209,198,65,251,0,0,0,67,251,0,0,0,41,220,3,6,7,3,78,138,43,8,63,63,14,67,6,1,224,3,2,0,2,3,0,0,63,2,238,3,0,1,0,240,3,0,1,0,209,66,252,0,0,0,210,65,252,0,0,0,174,67,252,0,0,0,209,66,252,0,0,0,181,162,67,252,0,0,0,209,66,251,0,0,0,210,65,251,0,0,0,174,67,251,0,0,0,209,66,251,0,0,0,181,162,67,251,0,0,0,41,220,3,14,5,3,93,68,93,68,14,67,6,1,226,3,2,1,2,5,0,0,77,3,238,3,0,1,0,250,3,0,1,0,244,3,0,0,0,11,209,65,252,0,0,0,210,160,209,65,251,0,0,0,189,32,210,158,162,175,76,252,0,0,0,209,65,251,0,0,0,210,160,209,65,252,0,0,0,189,32,210,158,162,175,76,251,0,0,0,201,209,197,65,252,0,0,0,67,252,0,0,0,209,197,65,251,0,0,0,67,251,0,0,0,41,220,3,20,7,3,8,128,128,8,63,63,14,67,6,1,228,3,1,1,1,2,0,0,27,2,238,3,0,1,0,252,3,0,0,0,209,65,251,0,0,0,201,209,209,65,252,0,0,0,67,251,0,0,0,209,197,67,252,0,0,0,41,220,3,28,4,3,38,63,38,14,67,6,1,230,3,4,0,4,3,4,0,72,4,254,3,0,1,0,128,4,0,1,0,130,4,0,1,0,132,4,0,1,0,222,3,0,1,226,3,2,1,224,3,1,1,228,3,3,1,221,209,210,240,14,221,211,212,240,14,222,210,189,13,240,14,222,212,189,16,240,14,223,210,209,240,14,223,212,211,240,14,224,209,239,14,221,211,210,240,14,221,209,212,240,14,222,210,189,17,240,14,222,212,189,21,240,14,223,210,211,240,14,223,212,209,240,14,224,211,239,41,220,3,33,15,3,28,28,33,33,28,28,23,28,28,33,33,28,28,18,14,67,6,1,232,3,2,0,2,4,0,0,31,2,238,3,0,1,0,134,4,0,1,0,209,210,184,157,71,189,24,160,209,210,183,157,71,189,16,160,175,209,210,182,157,71,189,8,160,175,209,210,71,175,40,220,3,49,4,3,43,48,48,14,67,6,1,234,3,2,14,2,5,4,0,180,4,16,136,4,0,1,0,138,4,0,1,0,140,4,0,0,0,142,4,0,1,0,254,3,0,2,0,130,4,0,3,0,128,4,0,4,0,132,4,0,5,0,144,4,0,6,0,146,4,0,7,0,148,4,0,8,0,150,4,0,9,0,152,4,0,10,0,154,4,0,11,0,156,4,0,12,0,248,3,0,13,0,236,3,7,1,224,3,1,1,232,3,5,1,230,3,4,1,210,151,4,75,0,0,0,171,234,5,221,210,239,214,11,209,182,71,181,162,76,252,0,0,0,209,181,71,181,162,76,251,0,0,0,201,11,209,184,71,181,162,76,252,0,0,0,209,183,71,181,162,76,251,0,0,0,202,11,197,65,252,0,0,0,76,252,0,0,0,197,65,251,0,0,0,76,251,0,0,0,203,197,204,11,198,65,252,0,0,0,76,252,0,0,0,198,65,251,0,0,0,76,251,0,0,0,195,4,198,195,5,210,233,196,6,188,158,195,7,56,168,0,0,0,17,56,164,0,0,0,17,189,8,33,1,0,33,1,0,195,8,222,199,11,1,101,109,111,115,76,252,0,0,0,1,117,101,115,112,76,251,0,0,0,240,14,222,194,4,11,1,97,114,111,100,76,252,0,0,0,1,109,111,100,110,76,251,0,0,0,240,14,222,200,11,1,101,103,121,108,76,252,0,0,0,1,97,114,101,110,76,251,0,0,0,240,14,222,194,5,11,1,98,100,101,116,76,252,0,0,0,1,115,101,116,121,76,251,0,0,0,240,14,181,195,9,194,9,194,7,163,234,67,11,223,210,194,9,185,157,240,76,252,0,0,0,223,210,194,9,240,76,251,0,0,0,195,10,222,194,5,194,10,240,14,224,199,194,4,200,194,5,34,4,0,14,224,199,194,4,200,194,5,34,4,0,14,222,199,194,10,240,14,189,8,148,9,236,184,194,8,188,194,6,73,181,195,11,194,9,194,6,163,234,19,194,8,194,11,145,195,11,113,210,194,9,145,195,9,71,73,236,232,194,11,188,163,234,12,194,8,194,11,145,195,11,181,73,236,240,11,194,8,188,71,189,24,160,194,8,187,71,189,16,160,175,194,8,186,71,189,8,160,175,194,8,185,71,175,76,252,0,0,0,194,8,184,71,189,24,160,194,8,183,71,189,16,160,175,194,8,182,71,189,8,160,175,194,8,181,71,175,76,251,0,0,0,195,12,222,194,5,194,12,240,14,224,199,194,4,200,194,5,34,4,0,14,224,199,194,4,200,194,5,34,4,0,14,222,199,194,12,240,14,222,200,11,181,76,252,0,0,0,190,255,0,76,251,0,0,0,240,14,224,199,194,4,200,194,5,34,4,0,14,224,199,194,4,200,194,5,34,4,0,14,224,199,194,4,200,194,5,34,4,0,14,224,199,194,4,200,194,5,34,4,0,14,199,195,13,222,194,13,194,4,240,14,222,194,13,200,240,14,222,194,13,194,5,240,14,194,13,40,220,3,55,72,3,53,24,8,53,53,13,53,53,13,58,58,23,58,58,178,18,53,53,13,23,53,53,13,18,53,53,13,23,53,53,13,18,38,8,63,53,13,38,58,58,33,23,13,33,18,38,83,13,33,48,13,8,168,168,13,38,58,58,33,18,33,43,13,58,58,58,58,18,38,33,38,14,67,6,1,236,3,1,3,1,5,0,0,56,4,158,4,0,1,0,160,4,0,0,0,162,4,0,1,0,164,4,0,2,0,56,19,1,0,0,56,20,1,0,0,209,239,239,213,56,168,0,0,0,17,209,233,33,1,0,201,181,202,209,233,203,198,199,163,234,19,197,198,113,209,66,21,1,0,0,198,36,1,0,73,147,1,236,234,197,40,220,3,130,1,6,3,73,63,53,73,23,14,67,6,0,204,3,2,5,2,8,0,1,89,7,172,4,0,1,0,174,4,0,1,0,176,4,0,0,0,178,4,0,1,0,180,4,0,2,0,162,4,0,3,0,164,4,0,4,0,209,66,58,0,0,0,189,16,36,1,0,205,233,183,156,234,6,191,0,197,157,201,197,233,183,155,202,56,168,0,0,0,17,210,33,1,0,203,181,204,181,195,4,200,198,163,234,40,199,198,200,158,182,158,113,56,27,1,0,0,197,66,28,1,0,0,194,4,194,4,183,157,36,2,0,189,16,240,73,182,148,3,183,148,4,236,213,199,40,220,3,144,1,13,3,58,33,30,28,58,13,19,28,158,18,18,13,7,2,48,14,67,6,0,206,3,2,0,2,4,0,0,31,2,238,3,0,1,0,134,4,0,1,0,209,210,184,157,71,189,24,160,209,210,183,157,71,189,16,160,175,209,210,182,157,71,189,8,160,175,209,210,71,175,40,220,3,163,1,4,3,43,48,48,14,67,6,0,208,3,2,5,2,4,0,0,82,7,186,4,0,1,0,188,4,0,1,0,190,4,0,0,0,192,4,0,1,0,180,4,0,2,0,164,4,0,3,0,162,4,0,4,0,56,230,0,0,0,209,185,240,201,56,230,0,0,0,210,185,240,202,56,168,0,0,0,17,189,8,33,1,0,203,181,204,181,195,4,194,4,197,233,163,234,15,199,200,113,197,194,4,71,73,147,3,147,4,236,236,181,195,4,194,4,198,233,163,234,15,199,200,113,198,194,4,71,73,147,3,147,4,236,236,199,40,220,3,170,1,13,3,48,49,63,14,53,43,13,24,53,43,13,23,14,67,6,0,210,3,2,6,2,5,0,0,149,1,8,186,4,0,1,0,188,4,0,1,0,190,4,0,0,0,192,4,0,1,0,180,4,0,2,0,164,4,0,3,0,162,4,0,4,0,136,4,0,5,0,56,230,0,0,0,209,189,8,240,201,56,230,0,0,0,210,189,8,240,202,56,168,0,0,0,17,189,16,33,1,0,203,181,204,181,195,4,194,4,197,233,163,234,15,199,200,113,197,194,4,71,73,147,3,147,4,236,236,181,195,4,194,4,198,233,163,234,15,199,200,113,198,194,4,71,73,147,3,147,4,236,236,56,172,0,0,0,17,185,33,1,0,196,5,181,113,56,231,0,0,0,199,181,240,73,194,5,182,113,56,231,0,0,0,199,185,240,73,194,5,183,113,56,231,0,0,0,199,189,8,240,73,194,5,184,113,56,231,0,0,0,199,189,12,240,73,194,5,40,220,3,189,1,18,3,53,54,63,14,53,43,13,24,53,43,13,24,53,68,68,73,73,14,67,6,0,212,3,3,0,3,4,0,0,25,3,158,4,0,1,0,180,1,0,1,0,134,1,0,1,0,209,66,33,1,0,0,181,210,36,2,0,211,157,209,66,33,1,0,0,210,36,1,0,157,40,220,3,214,1,1,3,14,67,6,0,214,3,2,4,2,4,0,1,212,1,6,196,4,0,1,0,198,4,0,1,0,200,4,0,0,0,202,4,0,1,0,162,4,0,2,0,176,4,0,3,0,56,230,0,0,0,210,189,8,240,201,56,168,0,0,0,17,209,233,197,233,157,33,1,0,206,66,69,0,0,0,209,36,1,0,14,198,66,69,0,0,0,197,209,233,36,2,0,14,193,17,57,38,1,0,0,14,181,203,199,189,16,163,234,43,198,199,71,66,58,0,0,0,189,16,36,1,0,208,233,183,156,234,6,191,0,200,157,204,56,38,1,0,0,200,157,17,57,38,1,0,0,14,147,2,236,209,56,234,0,0,0,56,38,1,0,0,189,8,4,39,1,0,0,241,17,57,38,1,0,0,14,56,234,0,0,0,56,38,1,0,0,189,13,4,39,1,0,0,241,17,57,38,1,0,0,14,56,234,0,0,0,56,38,1,0,0,189,18,4,39,1,0,0,241,17,57,38,1,0,0,14,56,234,0,0,0,56,38,1,0,0,189,23,4,39,1,0,0,241,17,57,38,1,0,0,14,56,38,1,0,0,40,220,3,218,1,16,3,54,73,58,69,44,43,68,33,29,73,24,128,128,128,128,7,2,48,14,67,6,0,216,3,0,4,0,4,0,1,93,4,136,4,0,0,0,208,4,0,1,0,210,4,0,2,0,198,4,0,3,0,56,233,0,0,0,56,226,0,0,0,56,227,0,0,0,240,201,56,232,0,0,0,56,226,0,0,0,56,227,0,0,0,240,202,56,229,0,0,0,66,245,0,0,0,197,56,228,0,0,0,36,2,0,203,56,178,0,0,0,199,65,252,0,0,0,239,191,0,160,56,178,0,0,0,199,65,251,0,0,0,239,175,204,56,235,0,0,0,198,200,35,2,0,220,3,242,1,8,3,88,89,53,8,28,24,148,10,36,1,128]"],"msg":null}

```