Browse Source

did a little cleanup

master
Andy Wallace 2 years ago
parent
commit
62a969ddbf
  1. 19
      database-debug.log
  2. 2750
      firebase-debug.log
  3. 6
      firestore-debug.log
  4. 70
      functions/game.js
  5. 29
      functions/index.js
  6. 141
      public/test.js
  7. 4
      pubsub-debug.log

19
database-debug.log

@ -3,12 +3,13 @@ WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (fil
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
17:11:10.617 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
17:11:10.771 [main] INFO com.firebase.server.forge.App$ - Listening at 127.0.0.1:9000
17:11:14.971 [NamespaceSystem-akka.actor.default-dispatcher-6] INFO com.firebase.core.namespace.NamespaceActor - chalice-5f2b0-default-rtdb successfully activated FBKV (SurveyIdle(0)) wait: 116ms, init: 0ms
17:11:16.117 [FirebaseWorkerPool-1-4] WARN com.firebase.core.persistence.backend.dummy.EmulatorMetadataPersistence - Multiple projectIds are not recommended in single project mode. Requested
namespace chalice-5f2b0, but the emulator is configured for chalice-5f2b0-default-rtdb. To
opt-out of single project mode add/set the single_project_mode: false property in
the firebase.json emulators config.
17:11:16.128 [NamespaceSystem-akka.actor.default-dispatcher-6] INFO com.firebase.core.namespace.NamespaceActor - chalice-5f2b0 successfully activated FBKV (SurveyIdle(0)) wait: 5ms, init: 0ms
17:11:24.795 [NamespaceSystem-blocking-namespace-operation-dispatcher-9] INFO com.firebase.core.namespace.StateManager - Namespace chalice-5f2b0-default-rtdb status Active to Active
17:38:34.267 [NamespaceSystem-akka.actor.default-dispatcher-4] INFO akka.event.slf4j.Slf4jLogger - Slf4jLogger started
17:38:34.404 [main] INFO com.firebase.server.forge.App$ - Listening at 127.0.0.1:9000
17:38:38.590 [NamespaceSystem-akka.actor.default-dispatcher-7] INFO com.firebase.core.namespace.NamespaceActor - chalice-5f2b0-default-rtdb successfully activated FBKV (SurveyIdle(0)) wait: 154ms, init: 0ms
17:38:38.590 [NamespaceSystem-akka.actor.default-dispatcher-5] INFO com.firebase.core.namespace.NamespaceActor - chalice-5f2b0 successfully activated FBKV (SurveyIdle(0)) wait: 154ms, init: 0ms
17:38:48.673 [NamespaceSystem-blocking-namespace-operation-dispatcher-19] INFO com.firebase.core.namespace.StateManager - Namespace chalice-5f2b0-default-rtdb status Active to Active
17:44:55.398 [Thread-0] INFO com.firebase.server.forge.App$ - Attempting graceful shutdown.
17:44:55.402 [NamespaceSystem-akka.actor.default-dispatcher-6] INFO com.firebase.core.namespace.Terminator$Terminator - 2 actors left to terminate: chalice-5f2b0, chalice-5f2b0-default-rtdb
17:44:55.404 [NamespaceSystem-akka.actor.default-dispatcher-8] INFO com.firebase.core.namespace.NamespaceActor - stopped namespace actor for chalice-5f2b0-default-rtdb
17:44:55.404 [NamespaceSystem-akka.actor.default-dispatcher-5] INFO com.firebase.core.namespace.NamespaceActor - stopped namespace actor for chalice-5f2b0
17:44:55.407 [Thread-0] INFO com.firebase.server.forge.App$ - Graceful shutdown complete.

2750
firebase-debug.log

File diff suppressed because it is too large

6
firestore-debug.log

@ -1,4 +1,4 @@
Sep 19, 2023 5:11:08 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
Sep 19, 2023 5:38:32 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketServer start
INFO: Started WebSocket server on ws://127.0.0.1:9150
API endpoint: http://127.0.0.1:8080
If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:
@ -7,5 +7,7 @@ If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment
Dev App Server is now running.
Sep 19, 2023 5:11:16 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketChannelHandler initChannel
Sep 19, 2023 5:38:38 PM com.google.cloud.datastore.emulator.firestore.websocket.WebSocketChannelHandler initChannel
INFO: Connected to new websocket client
*** shutting down gRPC server since JVM is shutting down
*** server shut down

70
functions/game.js

@ -10,9 +10,12 @@ let board = null;
//called as soon as we can in order to cache the board
exports.on_load = function(admin){
let ref = admin.database().ref('board');
//setup a listener for changes to the current board, and always store those changes in our board variable
let ref = admin.database().ref('current_state');
//this is kind of dumb because there should only be one entry here but whatever
//this will run every time the board is changed in the database
let query = ref.on("value", async function(snapshot) {
let found_board = false;
snapshot.forEach( data => {
@ -32,7 +35,7 @@ exports.on_load = function(admin){
}
exports.reset = async function(admin){ //should this maybe not be async?
exports.reset = function(admin){
console.log("I am resetting");
let info = {
@ -54,11 +57,11 @@ exports.reset = async function(admin){ //should this maybe not be async?
})
//write it!
const snapshot = await admin
const snapshot = admin
.database()
.ref("/")
.child("board")
.set({"info": info});
.child("current_state")
.set({"board": info});
}
exports.begin_resolve_input = function(admin, input){
@ -95,59 +98,6 @@ exports.begin_resolve_input = function(admin, input){
const snapshot = admin
.database()
.ref("/")
.child("board")
.set({"info": board});
.child("current_state")
.set({"board": board});
}
// exports.resolve_input = function(admin, input, board){
// console.log("i am reayd to resolve")
// console.log(board);
// //find the player
// let player = null;
// board.entities.forEach( ent => {
// if(ent.id == "player"){
// player = ent;
// }
// })
// let next_pos = {x: player.x, y:player.y};
// if (input == input_up) next_pos.y -= 1;
// if (input == input_down) next_pos.y += 1;
// if (input == input_left) next_pos.x -= 1;
// if (input == input_right) next_pos.x += 1;
// player.x = next_pos.x;
// player.y = next_pos.y;
// console.log("after move")
// console.log(board);
// //write it!
// const snapshot = admin
// .database()
// .ref("/")
// .child("board")
// .set({"info": board});
// }
// exports.get_board = async function(admin, extra_info, callback){
// console.log("start get board");
// let ref = await admin.database().ref('board');
// let board;
// //this is kind of dumb because there should only be one entry here but whatever
// let query = await ref.on("value", async function(snapshot) {
// snapshot.forEach( data => {
// console.log(" got the data");
// console.log(data.val())
// board = data.val();
// if (callback){
// callback(admin, extra_info, board)
// }
// });
// })
// // console.log("end get board");
// // return info;
// }

29
functions/index.js

@ -15,20 +15,6 @@ app.use(cors({
const game = require('./game.js');
/*
// I THINK THIS IS JUST FOR THE CLIENT SIDE
//Real Time Database
//https://firebase.google.com/docs/database/web/start (slightly modified)
const initializeApp = require("firebase/app");
const getDatabase = require("firebase/database");
const firebaseConfig = {
databaseURL: "https://chalice-5f2b0.firebaseio.com",
};
// Initialize Firebase
const firebase = initializeApp(firebaseConfig);
// Initialize Realtime Database and get a reference to the service
const database = getDatabase(firebase);
*/
//Real Time Database
// The Cloud Functions for Firebase SDK to setup triggers and logging.
@ -41,23 +27,12 @@ const admin = require("firebase-admin");
admin.initializeApp();
// // Create and deploy your first functions
// // https://firebase.google.com/docs/functions/get-started
//
// exports.helloWorld = functions.https.onRequest((request, response) => {
// console.log("hello hello hello")
// functions.logger.info("Hello logs!", {structuredData: true});
// //response.send("Hello from Firebase!");
// response.json( {response: "Hi there from hellow world" } );
// });
app.post('/testo', async(req, res) => {
console.log("I got a hit at testo");
res.json( {response: "I am a test" } );
})
//this appears to be called the very first time a request is made to this page
//I believe this runs as soon as the server starts however I won't see the output int he console until some other function is called
function setup(){
console.log("This is a setup function");
game.on_load(admin);
@ -165,7 +140,7 @@ exports.makeuppercase = onValueCreated(
*/
app.post('/reset_game', async(req, res) => {
app.post('/reset_game', (req, res) => {
game.reset(admin);
res.json( {response: true}); //do I even need this?
})

141
public/test.js

@ -35,31 +35,9 @@ const dbRef = firebase.database().ref();
//const usersRef = dbRef.child(`users`);
//keep a reference to the board
const board_ref = dbRef.child('board');
const cur_state_ref = dbRef.child('current_state');
function write_test(_text){
console.log(_text);
$.post(
endpoint+"add_message",
{text:_text},
function (response) {
console.log("I got:")
console.log(response)
}
)
}
function read_test(){
console.log( "reading" );
$.post(
endpoint+"read_testo",
{},
function (response) {
console.log("I read:")
console.log(response)
}
)
}
function reset_game(){
console.log( "resetting" );
@ -73,54 +51,18 @@ function reset_game(){
$( document ).ready(async function() {
console.log( "page loaded" );
//get the board
await board_ref.on("value", snap => {
//get the current state
//"value" will fire on page load and any time the value changes
await cur_state_ref.on("value", snap => {
console.log("get da board");
let info = snap.val();
console.log(info);
render_board(info.info);
let state = snap.val();
console.log(state);
render_board(state.board);
});
//other ways we can check
//"child_changed" - this fires when something gets changed, and only the changed value gets listed
//"child_added" - fires on page load or if a new child gets added
//this works to write to the DB (which I do not really need to do)
/*
firebase.database().ref('issues/').set({
desc: "yabbo gabbo",
id: "munch of crunk"
});
*/
/*
//this fires as soon as page is loaded
//this listed out all key values any time any one of them is changed
await usersRef.on("value", function(snapshot) {
console.log("I am looking at values");
snapshot.forEach(function(data) {
console.log("Key " + data.key + " has value: " + data.val());
});
})
//this fires when something gets changed, and only the changed value gets listed
await usersRef.on("child_changed", function(snapshot) {
console.log("I am changing of values");
snapshot.forEach(function(data) {
console.log("Key " + data.key + " now has value: " + data.val());
});
})
//this fires as soon as the page is loaded
await usersRef.on("child_added", snap => {
let user = snap.val();
console.log("child added: "+user.name)
// let $li = document.createElement("li");
// $li.innerHTML = user.name;
// $li.setAttribute("child-key", snap.key);
// $li.addEventListener("click", userClicked)
// userListUI.append($li);
});
*/
text_to_game_board("XXXX\nXXXX");
});
@ -132,9 +74,6 @@ this.addEventListener('keydown', e => {
if (e.keyCode == 38) send_input(input_up);
if (e.keyCode == 39) send_input(input_right);
if (e.keyCode == 40) send_input(input_down);
// if (event.keyCode == 13) {
// alert('hi.')
// }
})
//drawing the board to the screen
@ -171,22 +110,6 @@ function render_board(info){
board_holder.innerHTML = html;
}
function text_to_game_board(raw_text){
let html = "";
for (let i=0; i<raw_text.length; i++){
if (raw_text[i] == '\n') html += "<br>";
else{
html += "<p class='game_letter'>"+raw_text[i]+"</p>";
}
}
const board_holder = document.querySelector('#game_board_holder');
board_holder.innerHTML = html;
}
//sending input
function send_input(this_input){
console.log( "sending input" );
@ -195,4 +118,46 @@ function send_input(this_input){
{input: this_input},
function (response) {}
)
}
}
/*
bonus info and snippets
//this works to write to the DB (which I do not really need to do)
firebase.database().ref('issues/').set({
desc: "yabbo gabbo",
id: "munch of crunk"
});
function write_test(_text){
console.log(_text);
$.post(
endpoint+"add_message",
{text:_text},
function (response) {
console.log("I got:")
console.log(response)
}
)
}
function read_test(){
console.log( "reading" );
$.post(
endpoint+"read_testo",
{},
function (response) {
console.log("I read:")
console.log(response)
}
)
}
*/

4
pubsub-debug.log

@ -1,9 +1,9 @@
This is the Google Pub/Sub fake.
Implementation may be incomplete or differ from the real system.
Sep 19, 2023 5:11:11 PM com.google.cloud.pubsub.testing.v1.Main main
Sep 19, 2023 5:38:34 PM com.google.cloud.pubsub.testing.v1.Main main
INFO: IAM integration is disabled. IAM policy methods and ACL checks are not supported
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Sep 19, 2023 5:11:11 PM com.google.cloud.pubsub.testing.v1.Main main
Sep 19, 2023 5:38:35 PM com.google.cloud.pubsub.testing.v1.Main main
INFO: Server started, listening on 8085

Loading…
Cancel
Save