diff --git a/protobuf/PlayerSubmissionData.proto b/protobuf/PlayerSubmissionData.proto index 88b51ca..a4907a6 100644 --- a/protobuf/PlayerSubmissionData.proto +++ b/protobuf/PlayerSubmissionData.proto @@ -3,7 +3,6 @@ syntax = "proto3"; message PlayerSubmissionData { int32 score = 1; string name = 2; - string ip = 3; - repeated string words = 4; - bytes checksum = 5; + repeated string words = 3; + bytes checksum = 4; } diff --git a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/java/PlayerSubmissionDataOuterClass.java b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/java/PlayerSubmissionDataOuterClass.java index 11ed6a6..cfa1679 100644 --- a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/java/PlayerSubmissionDataOuterClass.java +++ b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/java/PlayerSubmissionDataOuterClass.java @@ -35,36 +35,24 @@ public interface PlayerSubmissionDataOrBuilder extends getNameBytes(); /** - * string ip = 3; - * @return The ip. - */ - java.lang.String getIp(); - /** - * string ip = 3; - * @return The bytes for ip. - */ - com.google.protobuf.ByteString - getIpBytes(); - - /** - * repeated string words = 4; + * repeated string words = 3; * @return A list containing the words. */ java.util.List getWordsList(); /** - * repeated string words = 4; + * repeated string words = 3; * @return The count of words. */ int getWordsCount(); /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index of the element to return. * @return The words at the given index. */ java.lang.String getWords(int index); /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index of the value to return. * @return The bytes of the words at the given index. */ @@ -72,7 +60,7 @@ public interface PlayerSubmissionDataOrBuilder extends getWordsBytes(int index); /** - * bytes checksum = 5; + * bytes checksum = 4; * @return The checksum. */ com.google.protobuf.ByteString getChecksum(); @@ -91,7 +79,6 @@ private PlayerSubmissionData(com.google.protobuf.GeneratedMessageV3.Builder b } private PlayerSubmissionData() { name_ = ""; - ip_ = ""; words_ = com.google.protobuf.LazyStringArrayList.EMPTY; checksum_ = com.google.protobuf.ByteString.EMPTY; } @@ -140,12 +127,6 @@ private PlayerSubmissionData( } case 26: { java.lang.String s = input.readStringRequireUtf8(); - - ip_ = s; - break; - } - case 34: { - java.lang.String s = input.readStringRequireUtf8(); if (!((mutable_bitField0_ & 0x00000001) != 0)) { words_ = new com.google.protobuf.LazyStringArrayList(); mutable_bitField0_ |= 0x00000001; @@ -153,7 +134,7 @@ private PlayerSubmissionData( words_.add(s); break; } - case 42: { + case 34: { checksum_ = input.readBytes(); break; @@ -244,48 +225,10 @@ public java.lang.String getName() { } } - public static final int IP_FIELD_NUMBER = 3; - private volatile java.lang.Object ip_; - /** - * string ip = 3; - * @return The ip. - */ - @java.lang.Override - public java.lang.String getIp() { - java.lang.Object ref = ip_; - if (ref instanceof java.lang.String) { - return (java.lang.String) ref; - } else { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - ip_ = s; - return s; - } - } - /** - * string ip = 3; - * @return The bytes for ip. - */ - @java.lang.Override - public com.google.protobuf.ByteString - getIpBytes() { - java.lang.Object ref = ip_; - if (ref instanceof java.lang.String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - ip_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - - public static final int WORDS_FIELD_NUMBER = 4; + public static final int WORDS_FIELD_NUMBER = 3; private com.google.protobuf.LazyStringList words_; /** - * repeated string words = 4; + * repeated string words = 3; * @return A list containing the words. */ public com.google.protobuf.ProtocolStringList @@ -293,14 +236,14 @@ public java.lang.String getIp() { return words_; } /** - * repeated string words = 4; + * repeated string words = 3; * @return The count of words. */ public int getWordsCount() { return words_.size(); } /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index of the element to return. * @return The words at the given index. */ @@ -308,7 +251,7 @@ public java.lang.String getWords(int index) { return words_.get(index); } /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index of the value to return. * @return The bytes of the words at the given index. */ @@ -317,10 +260,10 @@ public java.lang.String getWords(int index) { return words_.getByteString(index); } - public static final int CHECKSUM_FIELD_NUMBER = 5; + public static final int CHECKSUM_FIELD_NUMBER = 4; private com.google.protobuf.ByteString checksum_; /** - * bytes checksum = 5; + * bytes checksum = 4; * @return The checksum. */ @java.lang.Override @@ -348,14 +291,11 @@ public void writeTo(com.google.protobuf.CodedOutputStream output) if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { com.google.protobuf.GeneratedMessageV3.writeString(output, 2, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(ip_)) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 3, ip_); - } for (int i = 0; i < words_.size(); i++) { - com.google.protobuf.GeneratedMessageV3.writeString(output, 4, words_.getRaw(i)); + com.google.protobuf.GeneratedMessageV3.writeString(output, 3, words_.getRaw(i)); } if (!checksum_.isEmpty()) { - output.writeBytes(5, checksum_); + output.writeBytes(4, checksum_); } unknownFields.writeTo(output); } @@ -373,9 +313,6 @@ public int getSerializedSize() { if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(name_)) { size += com.google.protobuf.GeneratedMessageV3.computeStringSize(2, name_); } - if (!com.google.protobuf.GeneratedMessageV3.isStringEmpty(ip_)) { - size += com.google.protobuf.GeneratedMessageV3.computeStringSize(3, ip_); - } { int dataSize = 0; for (int i = 0; i < words_.size(); i++) { @@ -386,7 +323,7 @@ public int getSerializedSize() { } if (!checksum_.isEmpty()) { size += com.google.protobuf.CodedOutputStream - .computeBytesSize(5, checksum_); + .computeBytesSize(4, checksum_); } size += unknownFields.getSerializedSize(); memoizedSize = size; @@ -407,8 +344,6 @@ public boolean equals(final java.lang.Object obj) { != other.getScore()) return false; if (!getName() .equals(other.getName())) return false; - if (!getIp() - .equals(other.getIp())) return false; if (!getWordsList() .equals(other.getWordsList())) return false; if (!getChecksum() @@ -428,8 +363,6 @@ public int hashCode() { hash = (53 * hash) + getScore(); hash = (37 * hash) + NAME_FIELD_NUMBER; hash = (53 * hash) + getName().hashCode(); - hash = (37 * hash) + IP_FIELD_NUMBER; - hash = (53 * hash) + getIp().hashCode(); if (getWordsCount() > 0) { hash = (37 * hash) + WORDS_FIELD_NUMBER; hash = (53 * hash) + getWordsList().hashCode(); @@ -573,8 +506,6 @@ public Builder clear() { name_ = ""; - ip_ = ""; - words_ = com.google.protobuf.LazyStringArrayList.EMPTY; bitField0_ = (bitField0_ & ~0x00000001); checksum_ = com.google.protobuf.ByteString.EMPTY; @@ -608,7 +539,6 @@ public PlayerSubmissionDataOuterClass.PlayerSubmissionData buildPartial() { int from_bitField0_ = bitField0_; result.score_ = score_; result.name_ = name_; - result.ip_ = ip_; if (((bitField0_ & 0x00000001) != 0)) { words_ = words_.getUnmodifiableView(); bitField0_ = (bitField0_ & ~0x00000001); @@ -670,10 +600,6 @@ public Builder mergeFrom(PlayerSubmissionDataOuterClass.PlayerSubmissionData oth name_ = other.name_; onChanged(); } - if (!other.getIp().isEmpty()) { - ip_ = other.ip_; - onChanged(); - } if (!other.words_.isEmpty()) { if (words_.isEmpty()) { words_ = other.words_; @@ -824,82 +750,6 @@ public Builder setNameBytes( return this; } - private java.lang.Object ip_ = ""; - /** - * string ip = 3; - * @return The ip. - */ - public java.lang.String getIp() { - java.lang.Object ref = ip_; - if (!(ref instanceof java.lang.String)) { - com.google.protobuf.ByteString bs = - (com.google.protobuf.ByteString) ref; - java.lang.String s = bs.toStringUtf8(); - ip_ = s; - return s; - } else { - return (java.lang.String) ref; - } - } - /** - * string ip = 3; - * @return The bytes for ip. - */ - public com.google.protobuf.ByteString - getIpBytes() { - java.lang.Object ref = ip_; - if (ref instanceof String) { - com.google.protobuf.ByteString b = - com.google.protobuf.ByteString.copyFromUtf8( - (java.lang.String) ref); - ip_ = b; - return b; - } else { - return (com.google.protobuf.ByteString) ref; - } - } - /** - * string ip = 3; - * @param value The ip to set. - * @return This builder for chaining. - */ - public Builder setIp( - java.lang.String value) { - if (value == null) { - throw new NullPointerException(); - } - - ip_ = value; - onChanged(); - return this; - } - /** - * string ip = 3; - * @return This builder for chaining. - */ - public Builder clearIp() { - - ip_ = getDefaultInstance().getIp(); - onChanged(); - return this; - } - /** - * string ip = 3; - * @param value The bytes for ip to set. - * @return This builder for chaining. - */ - public Builder setIpBytes( - com.google.protobuf.ByteString value) { - if (value == null) { - throw new NullPointerException(); - } - checkByteStringIsUtf8(value); - - ip_ = value; - onChanged(); - return this; - } - private com.google.protobuf.LazyStringList words_ = com.google.protobuf.LazyStringArrayList.EMPTY; private void ensureWordsIsMutable() { if (!((bitField0_ & 0x00000001) != 0)) { @@ -908,7 +758,7 @@ private void ensureWordsIsMutable() { } } /** - * repeated string words = 4; + * repeated string words = 3; * @return A list containing the words. */ public com.google.protobuf.ProtocolStringList @@ -916,14 +766,14 @@ private void ensureWordsIsMutable() { return words_.getUnmodifiableView(); } /** - * repeated string words = 4; + * repeated string words = 3; * @return The count of words. */ public int getWordsCount() { return words_.size(); } /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index of the element to return. * @return The words at the given index. */ @@ -931,7 +781,7 @@ public java.lang.String getWords(int index) { return words_.get(index); } /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index of the value to return. * @return The bytes of the words at the given index. */ @@ -940,7 +790,7 @@ public java.lang.String getWords(int index) { return words_.getByteString(index); } /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index to set the value at. * @param value The words to set. * @return This builder for chaining. @@ -956,7 +806,7 @@ public Builder setWords( return this; } /** - * repeated string words = 4; + * repeated string words = 3; * @param value The words to add. * @return This builder for chaining. */ @@ -971,7 +821,7 @@ public Builder addWords( return this; } /** - * repeated string words = 4; + * repeated string words = 3; * @param values The words to add. * @return This builder for chaining. */ @@ -984,7 +834,7 @@ public Builder addAllWords( return this; } /** - * repeated string words = 4; + * repeated string words = 3; * @return This builder for chaining. */ public Builder clearWords() { @@ -994,7 +844,7 @@ public Builder clearWords() { return this; } /** - * repeated string words = 4; + * repeated string words = 3; * @param value The bytes of the words to add. * @return This builder for chaining. */ @@ -1012,7 +862,7 @@ public Builder addWordsBytes( private com.google.protobuf.ByteString checksum_ = com.google.protobuf.ByteString.EMPTY; /** - * bytes checksum = 5; + * bytes checksum = 4; * @return The checksum. */ @java.lang.Override @@ -1020,7 +870,7 @@ public com.google.protobuf.ByteString getChecksum() { return checksum_; } /** - * bytes checksum = 5; + * bytes checksum = 4; * @param value The checksum to set. * @return This builder for chaining. */ @@ -1034,7 +884,7 @@ public Builder setChecksum(com.google.protobuf.ByteString value) { return this; } /** - * bytes checksum = 5; + * bytes checksum = 4; * @return This builder for chaining. */ public Builder clearChecksum() { @@ -1110,10 +960,10 @@ public PlayerSubmissionDataOuterClass.PlayerSubmissionData getDefaultInstanceFor descriptor; static { java.lang.String[] descriptorData = { - "\n\032PlayerSubmissionData.proto\"`\n\024PlayerSu" + + "\n\032PlayerSubmissionData.proto\"T\n\024PlayerSu" + "bmissionData\022\r\n\005score\030\001 \001(\005\022\014\n\004name\030\002 \001(" + - "\t\022\n\n\002ip\030\003 \001(\t\022\r\n\005words\030\004 \003(\t\022\020\n\010checksum" + - "\030\005 \001(\014b\006proto3" + "\t\022\r\n\005words\030\003 \003(\t\022\020\n\010checksum\030\004 \001(\014b\006prot" + + "o3" }; descriptor = com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, @@ -1124,7 +974,7 @@ public PlayerSubmissionDataOuterClass.PlayerSubmissionData getDefaultInstanceFor internal_static_PlayerSubmissionData_fieldAccessorTable = new com.google.protobuf.GeneratedMessageV3.FieldAccessorTable( internal_static_PlayerSubmissionData_descriptor, - new java.lang.String[] { "Score", "Name", "Ip", "Words", "Checksum", }); + new java.lang.String[] { "Score", "Name", "Words", "Checksum", }); } // @@protoc_insertion_point(outer_class_scope) diff --git a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/kotlin/PlayerSubmissionDataKt.kt b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/kotlin/PlayerSubmissionDataKt.kt index 828e455..b5e16a8 100644 --- a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/kotlin/PlayerSubmissionDataKt.kt +++ b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/protobuf_gen/main/kotlin/PlayerSubmissionDataKt.kt @@ -54,23 +54,6 @@ object PlayerSubmissionDataKt { _builder.clearName() } - /** - * string ip = 3; - */ - var ip: kotlin.String - @JvmName("getIp") - get() = _builder.getIp() - @JvmName("setIp") - set(value) { - _builder.setIp(value) - } - /** - * string ip = 3; - */ - fun clearIp() { - _builder.clearIp() - } - /** * An uninstantiable, behaviorless type to represent the field in * generics. @@ -78,7 +61,7 @@ object PlayerSubmissionDataKt { @kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class) class WordsProxy private constructor() : com.google.protobuf.kotlin.DslProxy() /** - * repeated string words = 4; + * repeated string words = 3; * @return A list containing the words. */ val words: com.google.protobuf.kotlin.DslList @@ -87,7 +70,7 @@ object PlayerSubmissionDataKt { _builder.getWordsList() ) /** - * repeated string words = 4; + * repeated string words = 3; * @param value The words to add. */ @kotlin.jvm.JvmSynthetic @@ -96,7 +79,7 @@ object PlayerSubmissionDataKt { _builder.addWords(value) } /** - * repeated string words = 4; + * repeated string words = 3; * @param value The words to add. */ @kotlin.jvm.JvmSynthetic @@ -106,7 +89,7 @@ object PlayerSubmissionDataKt { add(value) } /** - * repeated string words = 4; + * repeated string words = 3; * @param values The words to add. */ @kotlin.jvm.JvmSynthetic @@ -115,7 +98,7 @@ object PlayerSubmissionDataKt { _builder.addAllWords(values) } /** - * repeated string words = 4; + * repeated string words = 3; * @param values The words to add. */ @kotlin.jvm.JvmSynthetic @@ -125,7 +108,7 @@ object PlayerSubmissionDataKt { addAll(values) } /** - * repeated string words = 4; + * repeated string words = 3; * @param index The index to set the value at. * @param value The words to set. */ @@ -134,7 +117,7 @@ object PlayerSubmissionDataKt { operator fun com.google.protobuf.kotlin.DslList.set(index: kotlin.Int, value: kotlin.String) { _builder.setWords(index, value) }/** - * repeated string words = 4; + * repeated string words = 3; */ @kotlin.jvm.JvmSynthetic @kotlin.jvm.JvmName("clearWords") @@ -142,7 +125,7 @@ object PlayerSubmissionDataKt { _builder.clearWords() } /** - * bytes checksum = 5; + * bytes checksum = 4; */ var checksum: com.google.protobuf.ByteString @JvmName("getChecksum") @@ -152,7 +135,7 @@ object PlayerSubmissionDataKt { _builder.setChecksum(value) } /** - * bytes checksum = 5; + * bytes checksum = 4; */ fun clearChecksum() { _builder.clearChecksum() diff --git a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/services/DataService.kt b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/services/DataService.kt index 5126377..dc19484 100644 --- a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/services/DataService.kt +++ b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/services/DataService.kt @@ -20,8 +20,8 @@ class DataService { @Autowired lateinit var ipRepository: IpRepository - fun saveScoreAndFlush(data: PlayerSubmissionDataOuterClass.PlayerSubmissionData) { - val ip = Ip(data.ip) + fun saveScoreAndFlush(ip: String, data: PlayerSubmissionDataOuterClass.PlayerSubmissionData) { + val ip = Ip(ip) ipRepository.saveAndFlush(ip) val name = Name(data.name, ip) nameRepository.saveAndFlush(name) diff --git a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/web/ScoreController.kt b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/web/ScoreController.kt index fb1968b..46af0cd 100644 --- a/wordtris-server/src/main/kotlin/khivy/wordtrisserver/web/ScoreController.kt +++ b/wordtris-server/src/main/kotlin/khivy/wordtrisserver/web/ScoreController.kt @@ -54,7 +54,7 @@ class ScoreController { @PutMapping(value = ["/submitscore"], consumes = ["application/x-protobuf"]) @ResponseBody - fun submitScore(@RequestBody body: PlayerSubmissionDataOuterClass.PlayerSubmissionData): ResponseEntity { + fun submitScore(@RequestBody body: PlayerSubmissionDataOuterClass.PlayerSubmissionData, request: HttpServletRequest): ResponseEntity { if (!submitScoreBucket.tryConsume(1)) { return ResponseEntity(HttpStatus.TOO_MANY_REQUESTS) @@ -81,14 +81,14 @@ class ScoreController { return ResponseEntity(HttpStatus.NOT_ACCEPTABLE) } - dataService.saveScoreAndFlush(body) + dataService.saveScoreAndFlush(request.remoteAddr, body) // Evicts the lowest score(s) that match the IP & Name combination. - val scoresMatchingIpAndName = dataService.scoreRepository.findScoresWithGivenIpAndNameNative(body.ip, body.name) + val scoresMatchingIpAndName = dataService.scoreRepository.findScoresWithGivenIpAndNameNative(request.remoteAddr, body.name) dataService.evictLowestScoresFromList(scoresMatchingIpAndName, scoresMatchingIpAndName.size - 1) // Evicts the lowest score(s) from the IP. - val scoresMatchingIp = dataService.scoreRepository.findScoresWithGivenIpNative(body.ip) + val scoresMatchingIp = dataService.scoreRepository.findScoresWithGivenIpNative(request.remoteAddr) if (MAX_SCORES_PER_IP < scoresMatchingIp.size) { dataService.evictLowestScoresFromList(scoresMatchingIp, scoresMatchingIp.size - MAX_SCORES_PER_IP) } diff --git a/wordtris/src/GameLoop.tsx b/wordtris/src/GameLoop.tsx index 9488ecb..bcac01c 100644 --- a/wordtris/src/GameLoop.tsx +++ b/wordtris/src/GameLoop.tsx @@ -65,7 +65,7 @@ import { PersonalHighScore } from "./components/PersonalHighScore"; // Terminology: https://tetris.fandom.com/wiki/Glossary // Declaration of game states. const stateMachine = createMachine({ - initial: "gameOver", + initial: "startingGame", states: { startingGame: { on: { START: "countdown" } }, countdown: { on: { DONE: "spawningBlock" } }, @@ -853,6 +853,7 @@ export function GameLoop() { const gameOverTextStyle = { color: "white", fontSize: LARGE_TEXT_SIZE, + textAlign: "center", // WebkitTextStroke: "0.2vmin", // WebkitTextStrokeColor: BOARD_CELL_COLOR, } as const; @@ -888,10 +889,10 @@ export function GameLoop() { - +
Game Over
- +
diff --git a/wordtris/src/components/GameOverOverlay.tsx b/wordtris/src/components/GameOverOverlay.tsx index 6327fa7..bdbfbb1 100644 --- a/wordtris/src/components/GameOverOverlay.tsx +++ b/wordtris/src/components/GameOverOverlay.tsx @@ -1,11 +1,7 @@ import * as React from "react"; -import { ReactNode } from "react"; -import { - MENU_TEXT_COLOR, - NORMAL_TEXT_SIZE, - PLAYER_COLOR, - UNIVERSAL_BORDER_RADIUS, -} from "../setup"; +import { ReactNode, useState } from "react"; +import { MENU_TEXT_COLOR, NORMAL_TEXT_SIZE, PLAYER_COLOR, SMALL_TEXT_SIZE, UNIVERSAL_BORDER_RADIUS, } from "../setup"; +import { submitScore } from "../util/webUtil"; export const GameOverOverlay = React.memo( ( @@ -41,7 +37,8 @@ export const GameOverOverlay = React.memo( ); export const PlayAgainButton = React.memo( - ({ stateHandler }: { stateHandler: { send: (arg0: string) => void } }) => { + ({ stateHandler, words }: { stateHandler: { send: (arg0: string) => void }, words: string[] }) => { + const buttonStyle = { cursor: "pointer", border: "none", @@ -53,16 +50,40 @@ export const PlayAgainButton = React.memo( marginTop: "0.4vmin", fontSize: NORMAL_TEXT_SIZE, }; + + const formStyle = { + size: "20", + fontSize: SMALL_TEXT_SIZE, + placeholder: "Enter name", + color: "black", + } as const; + + const [name, setName] = useState("" as string); + + const handleChange = event => { + setName(event.target.value); + console.log(typeof event.target.value) + }; + return ( -
{ - stateHandler.send("RESTART"); - }} - > - Play Again -
+ <> +
+ +
+
{ + submitScore(words.length, name, words); + stateHandler.send("RESTART"); + }} + > + Play Again +
+ ); }, ); diff --git a/wordtris/src/protobuf_gen/PlayerSubmissionData.ts b/wordtris/src/protobuf_gen/PlayerSubmissionData.ts index a2da6b4..3238727 100644 --- a/wordtris/src/protobuf_gen/PlayerSubmissionData.ts +++ b/wordtris/src/protobuf_gen/PlayerSubmissionData.ts @@ -4,193 +4,148 @@ import * as _m0 from "protobufjs/minimal"; export const protobufPackage = ""; export interface PlayerSubmissionData { - score: number; - name: string; - ip: string; - words: string[]; - checksum: Uint8Array; + score: number; + name: string; + words: string[]; + checksum: Uint8Array; } function createBasePlayerSubmissionData(): PlayerSubmissionData { - return { - score: 0, - name: "", - ip: "", - words: [], - checksum: new Uint8Array(), - }; + return { score: 0, name: "", words: [], checksum: new Uint8Array() }; } export const PlayerSubmissionData = { - encode( - message: PlayerSubmissionData, - writer: _m0.Writer = _m0.Writer.create(), - ): _m0.Writer { - if (message.score !== 0) { - writer.uint32(8).int32(message.score); - } - if (message.name !== "") { - writer.uint32(18).string(message.name); - } - if (message.ip !== "") { - writer.uint32(26).string(message.ip); - } - for (const v of message.words) { - writer.uint32(34).string(v!); - } - if (message.checksum.length !== 0) { - writer.uint32(42).bytes(message.checksum); - } - return writer; - }, + encode(message: PlayerSubmissionData, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { + if (message.score !== 0) { + writer.uint32(8).int32(message.score); + } + if (message.name !== "") { + writer.uint32(18).string(message.name); + } + for (const v of message.words) { + writer.uint32(26).string(v!); + } + if (message.checksum.length !== 0) { + writer.uint32(34).bytes(message.checksum); + } + return writer; + }, - decode( - input: _m0.Reader | Uint8Array, - length?: number, - ): PlayerSubmissionData { - const reader = input instanceof _m0.Reader - ? input - : new _m0.Reader(input); - let end = length === undefined ? reader.len : reader.pos + length; - const message = createBasePlayerSubmissionData(); - while (reader.pos < end) { - const tag = reader.uint32(); - switch (tag >>> 3) { - case 1: - message.score = reader.int32(); - break; - case 2: - message.name = reader.string(); - break; - case 3: - message.ip = reader.string(); - break; - case 4: - message.words.push(reader.string()); - break; - case 5: - message.checksum = reader.bytes(); - break; - default: - reader.skipType(tag & 7); - break; - } - } - return message; - }, + decode(input: _m0.Reader | Uint8Array, length?: number): PlayerSubmissionData { + const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); + let end = length === undefined ? reader.len : reader.pos + length; + const message = createBasePlayerSubmissionData(); + while (reader.pos < end) { + const tag = reader.uint32(); + switch (tag >>> 3) { + case 1: + message.score = reader.int32(); + break; + case 2: + message.name = reader.string(); + break; + case 3: + message.words.push(reader.string()); + break; + case 4: + message.checksum = reader.bytes(); + break; + default: + reader.skipType(tag & 7); + break; + } + } + return message; + }, - fromJSON(object: any): PlayerSubmissionData { - return { - score: isSet(object.score) ? Number(object.score) : 0, - name: isSet(object.name) ? String(object.name) : "", - ip: isSet(object.ip) ? String(object.ip) : "", - words: Array.isArray(object?.words) - ? object.words.map((e: any) => String(e)) - : [], - checksum: isSet(object.checksum) - ? bytesFromBase64(object.checksum) - : new Uint8Array(), - }; - }, + fromJSON(object: any): PlayerSubmissionData { + return { + score: isSet(object.score) ? Number(object.score) : 0, + name: isSet(object.name) ? String(object.name) : "", + words: Array.isArray(object?.words) ? object.words.map((e: any) => String(e)) : [], + checksum: isSet(object.checksum) ? bytesFromBase64(object.checksum) : new Uint8Array(), + }; + }, - toJSON(message: PlayerSubmissionData): unknown { - const obj: any = {}; - message.score !== undefined && (obj.score = Math.round(message.score)); - message.name !== undefined && (obj.name = message.name); - message.ip !== undefined && (obj.ip = message.ip); - if (message.words) { - obj.words = message.words.map((e) => e); - } else { - obj.words = []; - } - message.checksum !== undefined && - (obj.checksum = base64FromBytes( - message.checksum !== undefined - ? message.checksum - : new Uint8Array(), - )); - return obj; - }, + toJSON(message: PlayerSubmissionData): unknown { + const obj: any = {}; + message.score !== undefined && (obj.score = Math.round(message.score)); + message.name !== undefined && (obj.name = message.name); + if (message.words) { + obj.words = message.words.map((e) => e); + } else { + obj.words = []; + } + message.checksum !== undefined && + (obj.checksum = base64FromBytes(message.checksum !== undefined ? message.checksum : new Uint8Array())); + return obj; + }, - fromPartial, I>>( - object: I, - ): PlayerSubmissionData { - const message = createBasePlayerSubmissionData(); - message.score = object.score ?? 0; - message.name = object.name ?? ""; - message.ip = object.ip ?? ""; - message.words = object.words?.map((e) => e) || []; - message.checksum = object.checksum ?? new Uint8Array(); - return message; - }, + fromPartial, I>>(object: I): PlayerSubmissionData { + const message = createBasePlayerSubmissionData(); + message.score = object.score ?? 0; + message.name = object.name ?? ""; + message.words = object.words?.map((e) => e) || []; + message.checksum = object.checksum ?? new Uint8Array(); + return message; + }, }; declare var self: any | undefined; declare var window: any | undefined; declare var global: any | undefined; var globalThis: any = (() => { - if (typeof globalThis !== "undefined") { - return globalThis; - } - if (typeof self !== "undefined") { - return self; - } - if (typeof window !== "undefined") { - return window; - } - if (typeof global !== "undefined") { - return global; - } - throw "Unable to locate global object"; + if (typeof globalThis !== "undefined") { + return globalThis; + } + if (typeof self !== "undefined") { + return self; + } + if (typeof window !== "undefined") { + return window; + } + if (typeof global !== "undefined") { + return global; + } + throw "Unable to locate global object"; })(); function bytesFromBase64(b64: string): Uint8Array { - if (globalThis.Buffer) { - return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); - } else { - const bin = globalThis.atob(b64); - const arr = new Uint8Array(bin.length); - for (let i = 0; i < bin.length; ++i) { - arr[i] = bin.charCodeAt(i); - } - return arr; + if (globalThis.Buffer) { + return Uint8Array.from(globalThis.Buffer.from(b64, "base64")); + } else { + const bin = globalThis.atob(b64); + const arr = new Uint8Array(bin.length); + for (let i = 0; i < bin.length; ++i) { + arr[i] = bin.charCodeAt(i); } + return arr; + } } function base64FromBytes(arr: Uint8Array): string { - if (globalThis.Buffer) { - return globalThis.Buffer.from(arr).toString("base64"); - } else { - const bin: string[] = []; - arr.forEach((byte) => { - bin.push(String.fromCharCode(byte)); - }); - return globalThis.btoa(bin.join("")); - } + if (globalThis.Buffer) { + return globalThis.Buffer.from(arr).toString("base64"); + } else { + const bin: string[] = []; + arr.forEach((byte) => { + bin.push(String.fromCharCode(byte)); + }); + return globalThis.btoa(bin.join("")); + } } -type Builtin = - | Date - | Function - | Uint8Array - | string - | number - | boolean - | undefined; +type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; export type DeepPartial = T extends Builtin ? T - : T extends Array ? Array> - : T extends ReadonlyArray ? ReadonlyArray> - : T extends {} ? { [K in keyof T]?: DeepPartial } - : Partial; + : T extends Array ? Array> : T extends ReadonlyArray ? ReadonlyArray> + : T extends {} ? { [K in keyof T]?: DeepPartial } + : Partial; type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P - : - & P - & { [K in keyof P]: Exact } - & { [K in Exclude>]: never }; + : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; function isSet(value: any): boolean { - return value !== null && value !== undefined; + return value !== null && value !== undefined; } diff --git a/wordtris/src/util/webUtil.ts b/wordtris/src/util/webUtil.ts index 1e0bb69..a13340a 100644 --- a/wordtris/src/util/webUtil.ts +++ b/wordtris/src/util/webUtil.ts @@ -4,14 +4,12 @@ import { hash } from "fast-sha256"; export function submitScore( score: number, name: string, - ip: string, words: string[], checksum?: Uint8Array, ): Promise { const data = PlayerSubmissionData.encode({ score, name, - ip, words, checksum: checksum ? checksum! : hash(serializeWordsArray(words)), }).finish();