bug fix
This commit is contained in:
		
							parent
							
								
									6c0030bbe2
								
							
						
					
					
						commit
						74c53f17ae
					
				| @ -60,7 +60,7 @@ export default class Connection { | ||||
|     const ws = new Websock(uri); | ||||
|     this._ws = ws; | ||||
|     this._id = id; | ||||
|     console.log(new Date() + ": Conntecting to rendezvoous server: " + uri); | ||||
|     console.log(new Date() + ": Conntecting to rendezvoous server: " + uri + ", for " + id); | ||||
|     await ws.open(); | ||||
|     console.log(new Date() + ": Connected to rendezvoous server"); | ||||
|     const connType = rendezvous.ConnType.DEFAULT_CONN; | ||||
| @ -197,8 +197,8 @@ export default class Connection { | ||||
|       const msg = this._ws?.parseMessage(await this._ws?.next()); | ||||
|       if (msg?.hash) { | ||||
|         this._hash = msg?.hash; | ||||
|         if (!this._password) this.msgbox("input-password", "Password Required", ""); | ||||
|         await this.login(this._password); | ||||
|         this.msgbox("input-password", "Password Required", ""); | ||||
|       } else if (msg?.testDelay) { | ||||
|         const testDelay = msg?.testDelay; | ||||
|         if (!testDelay.fromClient) { | ||||
| @ -266,15 +266,13 @@ export default class Connection { | ||||
| 
 | ||||
|   async login(password: string | undefined, _remember: Boolean = false) { | ||||
|     this._password = password; | ||||
|     this.msgbox("connecting", "Connecting...", "Logging in..."); | ||||
|     if (password) { | ||||
|       const salt = this._hash?.salt; | ||||
|     if (salt && password) { | ||||
|       let p = hash([password, salt]); | ||||
|       let p = hash([password, salt!]); | ||||
|       const challenge = this._hash?.challenge; | ||||
|       if (challenge) { | ||||
|         p = hash([p, challenge]); | ||||
|       p = hash([p, challenge!]); | ||||
|       this.msgbox("connecting", "Connecting...", "Logging in..."); | ||||
|       await this._sendLoginMessage(p); | ||||
|       } | ||||
|     } else { | ||||
|       await this._sendLoginMessage(); | ||||
|     } | ||||
|  | ||||
| @ -13,6 +13,8 @@ window.getRgba = () => currentFrame; | ||||
| window.getLanguage = () => navigator.language; | ||||
| 
 | ||||
| export function msgbox(type, title, text) { | ||||
|   if (!events) return; | ||||
|   if (!type) return; | ||||
|   const text2 = text.toLowerCase(); | ||||
|   var hasRetry = type == "error" | ||||
|     && title == "Connection Error" | ||||
| @ -27,6 +29,7 @@ export function msgbox(type, title, text) { | ||||
| } | ||||
| 
 | ||||
| export function pushEvent(name, payload) { | ||||
|   if (!events) return; | ||||
|   payload.name = name; | ||||
|   events.push(payload); | ||||
| } | ||||
| @ -56,10 +59,12 @@ export function close() { | ||||
|   getConn()?.close(); | ||||
|   setConn(undefined); | ||||
|   currentFrame = undefined; | ||||
|   events = undefined; | ||||
| } | ||||
| 
 | ||||
| export function newConn() { | ||||
|   window.curConn?.close(); | ||||
|   events = []; | ||||
|   const conn = new Connection(); | ||||
|   setConn(conn); | ||||
|   return conn; | ||||
| @ -120,7 +125,7 @@ export function decrypt(signed, nonce, key) { | ||||
| export function decompress(compressedArray) { | ||||
|   const MAX = 1024 * 1024 * 64; | ||||
|   const MIN = 1024 * 1024; | ||||
|   let n = 30 * data.length; | ||||
|   let n = 30 * compressedArray.length; | ||||
|   if (n > MAX) { | ||||
|     n = MAX; | ||||
|   } | ||||
| @ -141,7 +146,7 @@ window.setByName = (name, value) => { | ||||
|   switch (name) { | ||||
|     case 'connect': | ||||
|       newConn(); | ||||
|       startConn(value); | ||||
|       startConn(String(value)); | ||||
|       break; | ||||
|     case 'login': | ||||
|       curConn.login(value.password, value.remember || false); | ||||
| @ -235,7 +240,7 @@ window.getByName = (name, arg) => { | ||||
|       return curConn.getRemember(); | ||||
|       break; | ||||
|     case 'event': | ||||
|       if (events.length) { | ||||
|       if (events && events.length) { | ||||
|         const e = events[0]; | ||||
|         events.splice(0, 1); | ||||
|         return JSON.stringify(e); | ||||
|  | ||||
| @ -28,6 +28,7 @@ if (app) { | ||||
| `;
 | ||||
| 
 | ||||
|   let player; | ||||
|   window.init(); | ||||
| 
 | ||||
|   document.body.onload = () => { | ||||
|     const host = document.querySelector('#host'); | ||||
| @ -55,11 +56,7 @@ if (app) { | ||||
|       document.querySelector('div#status').style.display = 'block'; | ||||
|       document.querySelector('div#connect').style.display = 'none'; | ||||
|       document.querySelector('div#text').innerHTML = 'Connecting ...'; | ||||
|       try { | ||||
|       await conn.start(id.value); | ||||
|       } catch (e) { | ||||
|         msgbox('error', 'Error', e); | ||||
|       } | ||||
|     }; | ||||
|     func(); | ||||
|   } | ||||
|  | ||||
| @ -96,10 +96,12 @@ export default class Websock { | ||||
|         resolve(this); | ||||
|       }; | ||||
|       this._websocket.onclose = (e) => { | ||||
|         if (this._status == 'open') { | ||||
|           reject(e); | ||||
|         } | ||||
|         this._status = e; | ||||
|         console.error("WebSock.onclose: " + e); | ||||
|         this._eventHandlers.close(e); | ||||
|         reject(e); | ||||
|       }; | ||||
|       this._websocket.onerror = (e) => { | ||||
|         if (!this._status) { | ||||
| @ -141,6 +143,7 @@ export default class Websock { | ||||
|   } | ||||
| 
 | ||||
|   close() { | ||||
|     this._status = ''; | ||||
|     if (this._websocket) { | ||||
|       if ( | ||||
|         this._websocket.readyState === WebSocket.OPEN || | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user