Skip to content

Commit

Permalink
Add socket chat server
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack253-png committed Oct 4, 2024
1 parent 09fdcf9 commit 15e05e8
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 4 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ dependencies {
include(implementation(project(path: ':commonutils')))
include(implementation(project(path: ':simulator')))
include(implementation(project(path: ':binfiles')))
include(implementation(project(path: ':chatserver')))
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings loom.layered() {
officialMojangMappings()
Expand Down
146 changes: 146 additions & 0 deletions chatserver/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '2.0.0'
id 'maven-publish'
id 'signing'
id 'org.jetbrains.dokka' version '1.9.10'
}

group = project.rootProject.maven_group
version = project.rootProject.mod_version

kotlin {
jvmToolchain(rootProject.jvm_version.toInteger())
compilerOptions {
verbose = true
allWarningsAsErrors = true
}
}

def targetJavaVersion = rootProject.jvm_version.toInteger()
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) {
it.options.release = targetJavaVersion
}
it.options.compilerArgs.add("-Werror")
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:${project.kotlin_coroutines_version}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${project.kotlin_version}")
implementation("org.apache.logging.log4j:log4j-api:${project.log4j2_version}")
implementation("org.apache.logging.log4j:log4j-core:${project.log4j2_version}")
implementation("org.fusesource.jansi:jansi:${project.jansi_version}")
implementation("org.jline:jline:${project.jline_version}")
}

test {

}

processResources {
inputs.property "version", project.rootProject.version
inputs.property "minecraft_version", project.rootProject.minecraft_version
inputs.property "loader_version", project.rootProject.loader_version
filteringCharset "UTF-8"

filesMatching("fabric.mod.json") {
expand "version": project.rootProject.version,
"minecraft_version": project.rootProject.minecraft_version,
"loader_version": project.rootProject.loader_version
}
}

jar {
archiveBaseName = "advancedfmk-chatserver"
}

task sourcesJar(type: Jar) {
from sourceSets.main.allSource
java.withSourcesJar()
archiveClassifier = "sources"
}

task javadocJar(type: Jar) {
dependsOn(javadoc)
from("build/dokka/javadoc")
archiveClassifier = "javadoc"
}

artifacts {
archives sourcesJar, javadocJar
}

var publish = new Properties()
rootProject.file('.gradle/publish.cfg').withInputStream { publish.load(it) }

def ossrhUserName = publish.getProperty('ossrhUserName')
def ossrhPassword = publish.getProperty('ossrhPassword')
def signKey = new String(publish.getProperty('signing.key').decodeBase64())
def signPassword = publish.getProperty('signing.password')

publishing {
publications {
maven(MavenPublication) {
groupId = group
artifactId = 'advancedfmk-chatserver'
version = version

from components.kotlin
artifact sourcesJar
artifact javadocJar

pom {
name = 'chatserver (Advanced Framework)'
description = 'Binary files reading & writing for Advanced Framework'
url = 'http://github.com/PrimogemStudio/Advanced-Framework'
licenses {
license {
name = 'GNU GENERAL PUBLIC LICENSE Version 3'
url = 'https://www.gnu.org/licenses/gpl-3.0.txt'
}
}
developers {
developer {
id = 'hackermdch'
name = 'hackermdch'
}


developer {
id = 'Jack253-png'
name = 'Coder 2'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:git://github.com/PrimogemStudio/Advanced-Framework.git'
developerConnection = 'scm:git:ssh://github.com/PrimogemStudio/Advanced-Framework.git'
url = 'https://github.com/PrimogemStudio/Advanced-Framework'
}
}
}
}

repositories {
maven {
name = "LocalMaven"
url = rootProject.layout.projectDirectory.dir("../maven")
}

maven {
name = "MavenCentral"
credentials {
username = ossrhUserName
password = ossrhPassword
}
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}
}
}

signing {
useInMemoryPgpKeys(signKey, signPassword)
sign publishing.publications.maven
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.primogemstudio.advancedfmk.chat

import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.net.ServerSocket
import java.net.Socket

fun eventLoop(s: Socket) {
while (true) {
val r = s.getInputStream()
val a = r.available()
if (a != 0) {
val data = r.readNBytes(a)
println(String(data, Charsets.UTF_8))
s.getOutputStream().write(data)
}
Thread.sleep(1000)

if (s.isClosed) break
}
}

@OptIn(DelicateCoroutinesApi::class)
fun main() {
val server = ServerSocket(32767)
val sockets = mutableListOf<Socket>()

while (true) {
val s = server.accept()
sockets.add(s)
GlobalScope.launch { eventLoop(s) }
}
}
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ antlr4_runtime_version=4.11.1
lwjgl_version=3.3.3
log4j2_version=2.22.1
graalvm_version=23.0.4
snakeyaml_version=2.2
snakeyaml_version=2.2
jansi_version=2.4.0
jline_version=3.18.0
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ include 'animerenderer'
include 'commonutils'
include 'flutter-ui'
include 'simulator'
include 'binfiles'
include 'binfiles'
include 'chatserver'
4 changes: 2 additions & 2 deletions simulator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ dependencies {
implementation(project(path: ':binfiles'))
implementation("org.apache.logging.log4j:log4j-api:${project.log4j2_version}")
implementation("org.apache.logging.log4j:log4j-core:${project.log4j2_version}")
implementation("org.fusesource.jansi:jansi:2.4.0")
implementation("org.jline:jline:3.18.0")
implementation("org.fusesource.jansi:jansi:${project.jansi_version}")
implementation("org.jline:jline:${project.jline_version}")
}

test {
Expand Down

0 comments on commit 15e05e8

Please sign in to comment.