Skip to content

Commit

Permalink
pre 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Snirozu committed Mar 11, 2024
1 parent da237ea commit 9fef4d0
Show file tree
Hide file tree
Showing 17 changed files with 208 additions and 62 deletions.
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
# Psych Engine - Online
Modified version of Psych Engine that adds multiplayer to it.
Psych Online is a modified Psych Engine with Online Multiplayer functionality!

This engine also has a [wiki!](https://github.com/Snirozu/Funkin-Psych-Online/wiki)
## Features
* Online Multiplayer (Public and LAN)
* Built-In Mod Downloader
* No Port Forwarding needed
* Game Modifiers
* Custom API
* Skins Support

If you want to use 0.6 of Psych Engine then go to [this repository](https://github.com/Snirozu/Funkin-Psych-Online-0.6)
##
This engine also has a [wiki!](https://github.com/Snirozu/Funkin-Psych-Online/wiki)
Check the Source Code of the server [here!](https://github.com/Snirozu/Funkin-Online-Server)

###### Psych Engine Commit: 5d0a66d
Binary file added assets/preload/sounds/fap.ogg
Binary file not shown.
3 changes: 0 additions & 3 deletions source/backend/ClientPrefs.hx
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ class SaveVariables {
public var trustedSources:Array<String> = ["https://gamebanana.com/"];
public var comboOffsetOP1:Array<Int> = [0, 0, 0, 0];
public var comboOffsetOP2:Array<Int> = [0, 0, 0, 0];
public var gapiRefreshToken:String = null;
public var gapiAccessToken:String = null;
public var gapiAccessExpires:Float = 0;

public function new()
{
Expand Down
32 changes: 20 additions & 12 deletions source/online/Downloader.hx
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,28 @@ class Downloader {
isConnected = true;

var urlFormat = getURLFormat(url);
try {
socket = !urlFormat.isSSL ? new Socket() : new sys.ssl.Socket();
socket.connect(new Host(urlFormat.domain), urlFormat.port);
}
catch (exc) {
if (!cancelRequested) {
Waiter.put(() -> {
Alert.alert('Downloading failed!', id + ': ' + exc);
});

socket = !urlFormat.isSSL ? new Socket() : new sys.ssl.Socket();
socket.setTimeout(5);

var tries = 0;
while (!cancelRequested) {
tries++;

try {
socket.connect(new Host(urlFormat.domain), urlFormat.port);
break;
}
catch (exc) {
if (tries >= 5) {
Waiter.put(() -> {
Alert.alert('Couldn\'t connect to the server after multiple tries!', id + ': ' + exc);
});
cancelRequested = true;
break;
}
}
doCancel();
return;
}
socket.setTimeout(10);

if (cancelRequested) {
doCancel();
Expand Down
30 changes: 30 additions & 0 deletions source/online/FunkinPoints.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package online;

import online.states.ResultsScreen;

@:build(online.Macros.getSetForwarder())
class FunkinPoints {
@:forwardField(FlxG.save.data.funkinPointsv1, 0)
public static var funkinPoints(get, null):Float;

public static function calcFP(accuracy:Float, misses:Float, noteDensity:Float, notesHit:Float, combo:Float, songSpeed:Float):Float {
if (accuracy <= 0)
return 0;
if (notesHit <= 0)
return 0;

var fp:Float = notesHit / noteDensity;
fp *= 1 + combo / 1000;
fp *= accuracy / (misses * 0.5 + 1) * (1 - noteDensity / 500);
fp *= songSpeed;
return Math.ffloor(fp);
}

public static function save(accuracy:Float, misses:Float, noteDensity:Float, notesHit:Float, combo:Float, songSpeed:Float) {
var gained:Float = online.FunkinPoints.calcFP(accuracy, misses, noteDensity, notesHit, combo, songSpeed);
funkinPoints += gained;
ResultsScreen.gainedPoints = gained;
FlxG.save.flush();
GameClient.send("updateFP", funkinPoints);
}
}
7 changes: 6 additions & 1 deletion source/online/GameClient.hx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import haxe.Http;
import sys.io.File;
import sys.FileSystem;
import online.states.OnlineState;
//import io.colyseus.error.HttpException; 0.15.3 doesn't work
import io.colyseus.error.MatchMakeError;
import lime.app.Application;
import io.colyseus.events.EventHandler;
Expand Down Expand Up @@ -134,7 +135,11 @@ class GameClient {
}

static function getOptions(asHost:Bool):Map<String, Dynamic> {
var options:Map<String, Dynamic> = ["name" => ClientPrefs.data.nickname, "version" => MainMenuState.psychOnlineVersion];
var options:Map<String, Dynamic> = [
"name" => ClientPrefs.data.nickname,
"version" => MainMenuState.psychOnlineVersion,
"points" => FunkinPoints.funkinPoints
];

if (ClientPrefs.data.modSkin != null && ClientPrefs.data.modSkin.length >= 2) {
options.set("skinMod", ClientPrefs.data.modSkin[0]);
Expand Down
2 changes: 1 addition & 1 deletion source/online/Macros.hx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Macros {
access: fieldAccess,
kind: FieldType.FFun({
args: [],
expr: macro return ${meta.params[0]}
expr: macro return ${meta.params[0]} ?? ${meta.params[1]}
}),
pos: pos,
});
Expand Down
6 changes: 6 additions & 0 deletions source/online/schema/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,10 @@ class Player extends Schema {

@:type("string")
public var skinURL:String = null;

@:type("number")
public var points:Dynamic = 0;

@:type("string")
public var status:String = null;
}
15 changes: 14 additions & 1 deletion source/online/states/OptionsState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ class OptionsState extends MusicBeatState {

var nicknameOption:InputOption;
items.add(nicknameOption = new InputOption("Nickname", "Set your nickname here!", "Boyfriend", true, text -> {
curOption.input.text = curOption.input.text.trim().substr(0, 20);
if (curOption.input.text == "")
ClientPrefs.data.nickname = "Boyfriend";
ClientPrefs.data.nickname = curOption.input.text;
else
ClientPrefs.data.nickname = curOption.input.text;
ClientPrefs.saveSettings();
}));
nicknameOption.input.text = ClientPrefs.data.nickname;
Expand All @@ -60,6 +62,17 @@ class OptionsState extends MusicBeatState {
serverOption.screenCenter(X);
serverOption.ID = i++;

// var titleOption:InputOption;
// items.add(titleOption = new InputOption("Title", "This will be shown below your name! (Max 20 characters)", ClientPrefs.data.playerTitle, text -> {
// curOption.input.text = curOption.input.text.trim().substr(0, 20);
// ClientPrefs.data.playerTitle = curOption.input.text;
// ClientPrefs.saveSettings();
// }));
// titleOption.input.text = ClientPrefs.data.playerTitle;
// titleOption.y = serverOption.y + serverOption.height + 50;
// titleOption.screenCenter(X);
// titleOption.ID = i++;

var skinsOption:InputOption;
items.add(skinsOption = new InputOption("Skin", "Choose your skin here!", null, false));
skinsOption.y = serverOption.y + serverOption.height + 50;
Expand Down
29 changes: 29 additions & 0 deletions source/online/states/ResultsScreen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import objects.Character;
import online.schema.Player;

class ResultsScreen extends MusicBeatState {
public static var gainedPoints:Float = 0;

var disableInput = true;

var win:FlxSprite;
Expand All @@ -16,6 +18,8 @@ class ResultsScreen extends MusicBeatState {
var p1Text:Alphabet;
var p2Text:Alphabet;

var gainedText:FlxText;

var p1Accuracy:Float;
var p2Accuracy:Float;

Expand Down Expand Up @@ -125,6 +129,13 @@ class ResultsScreen extends MusicBeatState {
back.alpha = 0;
add(back);

gainedText = new FlxText(0, 0, 0, '+ ${gainedPoints}FP');
gainedText.setFormat(null, 40, FlxColor.WHITE, LEFT, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);
//gainedText.setPosition(FlxG.width - gainedText.width - 20, FlxG.height - gainedText.height - 20);
gainedText.setPosition(30, FlxG.height - gainedText.height - 25);
gainedText.visible = false;
add(gainedText);

if (!GameClient.isConnected()) {
MusicBeatState.switchState(new OnlineState());
return;
Expand Down Expand Up @@ -220,13 +231,29 @@ class ResultsScreen extends MusicBeatState {
FlxTween.tween(lose, {alpha: 1, angle: 3}, 0.5, {ease: FlxEase.quadInOut});
FlxTween.tween(lose, {angle: 0}, 0.2, {ease: FlxEase.quadInOut});

if (gainedPoints > 0) {
gainedText.visible = true;
FlxG.sound.play(Paths.sound('fap'));
if (ClientPrefs.data.flashing)
FlxFlicker.flicker(gainedText, 0.4, 0.05, true);
FlxTween.tween(gainedText, {alpha: 0.2}, 2, {ease: FlxEase.quadInOut});

new FlxTimer().start(2, (t) -> {
FlxTween.tween(gainedText, {x: back.x, y: back.y - 50, size: 25}, 1, {ease: FlxEase.quartOut});
});
}

gainedPoints = 0;

if (ClientPrefs.data.flashing) {
flickerLoop();
return;
}
spotlight.visible = true;

});

GameClient.send("status", "Viewing results");
}

function flickerLoop() {
Expand All @@ -252,6 +279,8 @@ class ResultsScreen extends MusicBeatState {
disableInput = true;
back.animation.play('press');
back.offset.set(80, 50);
if (gainedText.visible)
FlxTween.tween(gainedText, {alpha: 0}, 0.2, {ease: FlxEase.quadInOut});
new FlxTimer().start(0.5, (t) -> {
GameClient.clearOnMessage();
MusicBeatState.switchState(new Room());
Expand Down
71 changes: 32 additions & 39 deletions source/online/states/Room.hx
Original file line number Diff line number Diff line change
Expand Up @@ -205,23 +205,23 @@ class Room extends MusicBeatState {

// POST STAGE

player1Text = new FlxText(0, 40, 0, "PLAYER 1");
player1Text = new FlxText(0, 100, 0, "PLAYER 1");
player1Text.setFormat("VCR OSD Mono", 25, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);

player1Bg = new FlxSprite(-1000);
player1Bg.makeGraphic(1, 1, 0xA4000000);
player1Bg.updateHitbox();
player1Bg.y = player1Text.y;
player1Bg.y = player1Text.y - 30;
groupHUD.add(player1Bg);
groupHUD.add(player1Text);

player2Text = new FlxText(0, 40, 0, "PLAYER 2");
player2Text = new FlxText(0, 100, 0, "PLAYER 2");
player2Text.setFormat("VCR OSD Mono", 25, FlxColor.WHITE, CENTER, FlxTextBorderStyle.OUTLINE, FlxColor.BLACK);

player2Bg = new FlxSprite(-1000);
player2Bg.makeGraphic(1, 1, 0xA4000000);
player2Bg.updateHitbox();
player2Bg.y = player2Text.y;
player2Bg.y = player2Text.y - 30;
groupHUD.add(player2Bg);
groupHUD.add(player2Text);

Expand Down Expand Up @@ -374,6 +374,8 @@ class Room extends MusicBeatState {
FlxG.autoPause = false;

verifyDownloadMod(true);

GameClient.send("status", "In the Lobby");
}

function loadCharacter(isP1:Bool, ?enableDownload:Bool = true) {
Expand Down Expand Up @@ -455,6 +457,12 @@ class Room extends MusicBeatState {
super.openSubState(obj);
}

override function closeSubState() {
super.closeSubState();

GameClient.send("status", "In the Lobby");
}

var optionShake:FlxTween;

var elapsedShit = 3.;
Expand Down Expand Up @@ -758,46 +766,18 @@ class Room extends MusicBeatState {
songNameBg.updateHitbox();
songNameBg.x = songName.x;

player1Text.text =
GameClient.room.state.player1.name + "\n" +
"Ping: " + GameClient.room.state.player1.ping + "ms" + "\n\n" +
"Last Song Summary\n" +
"Score: " + GameClient.room.state.player1.score + "\n" +
"Accuracy: " + GameClient.getPlayerAccuracyPercent(GameClient.room.state.player1) + "%\n" +
"Sicks: " + GameClient.room.state.player1.sicks + "\n" +
"Goods: " + GameClient.room.state.player1.goods + "\n" +
"Bads: " + GameClient.room.state.player1.bads + "\n" +
"Shits: " + GameClient.room.state.player1.shits + "\n" +
"Misses: " + GameClient.room.state.player1.misses + "\n";
if (GameClient.room.state.player1.isReady)
player1Text.text += "\nREADY";
else
player1Text.text += "\nNOT READY";
player1Text.text = returnPlayerText(GameClient.room.state.player1);

if (GameClient.room.state.player2 != null && GameClient.room.state.player2.name != "") {
player2Text.alpha = 1;
p2.colorTransform.redOffset = 0;
p2.colorTransform.greenOffset = 0;
p2.colorTransform.blueOffset = 0;
p2.alpha = 1;
player2Text.text =
GameClient.room.state.player2.name + "\n" +
"Ping: " + GameClient.room.state.player2.ping + "ms" + "\n\n" +
"Last Song Summary\n" +
"Score: " + GameClient.room.state.player2.score + "\n" +
"Accuracy: " + GameClient.getPlayerAccuracyPercent(GameClient.room.state.player2) + "%\n" +
"Sicks: " + GameClient.room.state.player2.sicks + "\n" +
"Goods: " + GameClient.room.state.player2.goods + "\n" +
"Bads: " + GameClient.room.state.player2.bads + "\n" +
"Shits: " + GameClient.room.state.player2.shits + "\n" +
"Misses: " + GameClient.room.state.player2.misses + "\n";
if (GameClient.room.state.player2.isReady)
player2Text.text += "\nREADY";
else
player2Text.text += "\nNOT READY";
player2Text.text = returnPlayerText(GameClient.room.state.player2);
}
else {
player2Text.text = "WAITING FOR OPPONENT...";
player2Text.text = "WAITING FOR OPPONENT";
player2Text.alpha = 0.8;
p2.colorTransform.redOffset = -255;
p2.colorTransform.greenOffset = -255;
Expand Down Expand Up @@ -827,14 +807,15 @@ class Room extends MusicBeatState {
p2.alpha = 0.5;
}

player1Bg.x = player1Text.x;
player1Bg.scale.set(player1Text.width, player1Text.height);
player1Bg.scale.set(FlxMath.bound(player1Text.width, 300), player1Text.height + 60);
player1Bg.updateHitbox();

player2Bg.x = player2Text.x;
player2Bg.scale.set(player2Text.width, player2Text.height);
player2Bg.scale.set(FlxMath.bound(player2Text.width, 300), player2Text.height + 60);
player2Bg.updateHitbox();

player1Bg.x = 250 - player1Bg.width / 2;
player2Bg.x = 700 - player2Bg.width / 2;

switch (curSelected) {
case 0:
itemTip.text = " - SETTINGS - \nOpens server settings.\n\n(Keybind: SHIFT)";
Expand All @@ -860,6 +841,18 @@ class Room extends MusicBeatState {
itemTipBg.updateHitbox();
}

function returnPlayerText(player:Player) {
return
player.name + "\n\n" +
//player.title + "\n\n" + //completely unsure about that
"Statistics\n" +
"Points: " + player.points + "\n" +
"Ping: " + player.ping + "ms" + "\n\n" +
player.status + "\n" +
(!player.isReady ? "NOT " : "") + "READY"
;
}

function changeSelection(diffe:Int) {
curSelected += diffe;

Expand Down
Loading

0 comments on commit 9fef4d0

Please sign in to comment.