import kotlinx.coroutines.launch
import kotlinx.html.FormEncType
import kotlinx.html.FormMethod
-import kotlinx.html.dom.create
+import kotlinx.html.dom.append
import kotlinx.html.hiddenInput
import kotlinx.html.js.form
+import kotlinx.html.style
suspend fun setupBackground() {
val camera = PerspectiveCamera(69, window.aspectRatio, 0.01, 1_000)
}
private suspend fun enterGame(connectToken: String): Nothing {
- document.create.form(action = "/play", method = FormMethod.post, encType = FormEncType.applicationXWwwFormUrlEncoded) {
+ document.body!!.append.form(action = "/play", method = FormMethod.post, encType = FormEncType.applicationXWwwFormUrlEncoded) {
+ style = "display:none"
hiddenInput {
name = "token"
value = connectToken
redirect("/me")
}
- get("/logout") {
+ post("/logout") {
call.getUserSession()?.let { sess ->
launch {
val newTime = Instant.now().minusMillis(100)
redirect("/")
}
- get("/logout/{id}") {
+ post("/logout/{id}") {
val id = Id<UserSession>(call.parameters.getOrFail("id"))
call.getUserSession()?.let { sess ->
launch {
redirect("/me/manage")
}
- get("/logout-all") {
+ post("/logout-all") {
call.getUserSession()?.let { sess ->
launch {
val newTime = Instant.now().minusMillis(100)
redirect("/me/manage")
}
- get("/clear-expired/{id}") {
+ post("/clear-expired/{id}") {
val id = Id<UserSession>(call.parameters.getOrFail("id"))
call.getUserSession()?.let { sess ->
launch {
redirect("/me/manage")
}
- get("/clear-all-expired") {
+ post("/clear-all-expired") {
call.getUserSession()?.let { sess ->
launch {
val now = Instant.now()
--- /dev/null
+package starshipfights.info
+
+import kotlinx.html.A
+
+var A.method: String?
+ get() = attributes["data-method"]
+ set(value) {
+ if (value != null)
+ attributes["data-method"] = value
+ else
+ attributes.remove("data-method")
+ }
}
}
-data class NavLink(val to: String, val text: String) : NavItem() {
+data class NavLink(val to: String, val text: String, val isPost: Boolean = false) : NavItem() {
override fun DIV.display() {
a(href = to) {
+ if (isPost)
+ method = "post"
+text
}
}
NavLink("/me", user.profileName),
NavLink("/me/manage", "User Preferences"),
NavLink("/lobby", "Enter Game Lobby"),
- NavLink("/logout", "Log Out"),
+ NavLink("/logout", "Log Out", isPost = true),
)
} + listOf(
NavHead("External Information"),
+"Current Session"
br
}
- a(href = "/logout/${session.id}") { +"Logout" }
+ a(href = "/logout/${session.id}") {
+ method = "post"
+ +"Logout"
+ }
}
}
}
tr {
td {
colSpan = if (currentUser.logIpAddresses) "3" else "2"
- a(href = "/logout-all") { +"Logout All" }
+ a(href = "/logout-all") {
+ method = "post"
+ +"Logout All"
+ }
}
}
expiredSessions.forEach { session ->
+session.expiration.toEpochMilli().toString()
}
br
- a(href = "/clear-expired/${session.id}") { +"Clear" }
+ a(href = "/clear-expired/${session.id}") {
+ method = "post"
+ +"Clear"
+ }
}
}
}
tr {
td {
colSpan = if (currentUser.logIpAddresses) "3" else "2"
- a(href = "/clear-all-expired") { +"Clear All Expired Sessions" }
+ a(href = "/clear-all-expired") {
+ method = "post"
+ +"Clear All Expired Sessions"
+ }
}
}
}
+admiral.faction.currencyName
+"s"
br
- a(href = "/admiral/${admiralId}/buy/${st.toUrlSlug()}") {
- +"Buy"
- }
+ a(href = "/admiral/${admiralId}/buy/${st.toUrlSlug()}") { +"Buy" }
}
}
}
window.addEventListener("load", function () {
+ // Load and render OBJ meshes
if (!window.sfShipMeshViewer) return;
const canvases = document.getElementsByTagName("canvas");
});
window.addEventListener("load", function () {
+ // Localize dates and times
const moments = document.getElementsByClassName("moment");
for (let moment of moments) {
let date = new Date(Number(moment.innerHTML.trim()));
});
window.addEventListener("load", function () {
+ // Generate random admiral names
if (!window.sfAdmiralNameGen) return;
const nameBox = document.getElementById("name");
});
window.addEventListener("load", function () {
+ // Indicate maximum and used length of <textarea>s
const textareas = document.getElementsByTagName("textarea");
for (let textarea of textareas) {
if (!textarea.hasAttribute("maxLength")) continue;
updateIndicator();
}
});
+
+window.addEventListener("load", function () {
+ // Allow POSTing with <a>s
+ const anchors = document.getElementsByTagName("a");
+ for (let anchor of anchors) {
+ const method = anchor.getAttribute("data-method");
+ if (method == null) continue;
+
+ anchor.onclick = e => {
+ e.preventDefault();
+
+ let form = document.createElement("form");
+ form.style.display = "none";
+ form.action = anchor.href;
+ form.method = method;
+
+ document.body.append(form);
+ form.submit();
+ };
+ }
+});