Skip to content

Commit

Permalink
Update license
Browse files Browse the repository at this point in the history
  • Loading branch information
Red1C3 committed Feb 12, 2023
1 parent 29348c5 commit c4140e0
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 213 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Mohammad Issawi
Copyright (c) 2023 Mohammad Issawi

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
59 changes: 18 additions & 41 deletions client/client.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/*
MIT License
# Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package client

import (
Expand Down Expand Up @@ -96,12 +73,12 @@ func Start() {
}
func closeConnection(sendCloseMsg bool) {
fmt.Println("Closing connection...")
if sendCloseMsg{
_, err := client.connection.Write([]byte{CLOSE_MSG})
if err != nil {
log.Print("Failed to send closing message to server, error:", err.Error())
}
}
if sendCloseMsg {
_, err := client.connection.Write([]byte{CLOSE_MSG})
if err != nil {
log.Print("Failed to send closing message to server, error:", err.Error())
}
}
err := client.connection.Close()
if err != nil {
log.Fatal("Failed to close connection to server")
Expand All @@ -115,14 +92,14 @@ func startGame() {
for {
select {
case <-closeChannel:
closeConnection(false)
closeConnection(false)
return
default:
}
updateDrawInfo()
if eventsHandler(drawInfo) == 1 {
closeChannel<-true
closeConnection(true)
closeChannel <- true
closeConnection(true)
return
}
}
Expand All @@ -138,9 +115,9 @@ func eventsHandler(dI game.CDrawInfo) int {
var err error
switch event.Key {
case 'u':
_, err = client.connection.Write([]byte{DATA_MSG,1})
_, err = client.connection.Write([]byte{DATA_MSG, 1})
case 'd':
_, err = client.connection.Write([]byte{DATA_MSG,0})
_, err = client.connection.Write([]byte{DATA_MSG, 0})
}
if err != nil {
log.Fatal("Failed to send direction byte to server, error:", err.Error())
Expand All @@ -159,19 +136,19 @@ func listenToServer() {
var b [64]byte

for {
select{
case <-closeChannel:
return
default:
}
select {
case <-closeChannel:
return
default:
}
n, err := client.connection.Read(b[:])
if err != nil {
log.Print("Failed to read from server, error:", err.Error())
}
switch b[0] {
case CLOSE_MSG:
closeChannel<-true
return
closeChannel <- true
return
case DATA_MSG:
buffer.Reset()
_, err = buffer.Write(b[1:])
Expand Down
25 changes: 1 addition & 24 deletions game/ball.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/*MIT License
Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package game

import (
Expand Down Expand Up @@ -49,7 +26,7 @@ func NewBall() Ball {
return b
}

//game physics, called every frame
// game physics, called every frame
func (b *Ball) Update(dt float64, p []Player, resetFun func(i float64)) {
//checks if any of the players scored
if b.Pos[0] < -32 && b.Velocity[0] < 0 {
Expand Down
33 changes: 5 additions & 28 deletions game/game.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/*MIT License
Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package game

// #cgo pkg-config: glfw3 glew
Expand All @@ -37,12 +14,12 @@ import (
"time"
)

//geomatric line, formatted as y = a * x + b
// geomatric line, formatted as y = a * x + b
type line struct {
a, b float64
}

//game constants, change for different difficulty
// game constants, change for different difficulty
const (
playerSpeed = 30.0
ScoreGain = 1.01
Expand Down Expand Up @@ -87,7 +64,7 @@ func gameLogic() {
}
}

//Updates the structure sent to C code to draw properlys
// Updates the structure sent to C code to draw properlys
func updateDrawInfo() {
if gameBall.Pos[0] > players[0].Pos[0] && gameBall.Pos[0] < players[1].Pos[0] {
drawInfo.ball[0] = C.float(gameBall.Pos[0])
Expand All @@ -102,7 +79,7 @@ func updateDrawInfo() {
drawInfo.scores[1] = C.int(players[1].Score)
}

//Handles C events
// Handles C events
func eventsHandler(dI C.DrawInfo) int {
event := C.loop(dI)
//if resat, wait for (ResetTime) seconds before starting...
Expand Down Expand Up @@ -137,7 +114,7 @@ func eventsHandler(dI C.DrawInfo) int {
}
}

//called when a Player scores
// called when a Player scores
func reset(i float64) {
gameBall.Pos = [2]float64{i * 25, 0}
//create a new Velocity vector with the same speed of the current one
Expand Down
23 changes: 0 additions & 23 deletions game/player.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/*MIT License
Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package game

type Player struct {
Expand Down
23 changes: 0 additions & 23 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/*MIT License
Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/

package main

import (
Expand Down
25 changes: 1 addition & 24 deletions server/client.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/*
MIT License
# Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package server

import (
Expand All @@ -47,7 +24,7 @@ func listenToClient() {
}
switch buffer[0] {
case client.CLOSE_MSG:
delete(gameLobby.clients,addr.String())
delete(gameLobby.clients, addr.String())
closeChannel <- true
case client.DATA_MSG:
var dir int
Expand Down
28 changes: 2 additions & 26 deletions server/lobby.go
Original file line number Diff line number Diff line change
@@ -1,35 +1,11 @@
/*
MIT License
# Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package server

type lobby struct {
clients map[string]*clientStr
clients map[string]*clientStr
}

func newLobby() lobby {
return lobby{
clients: make(map[string]*clientStr),
clients: make(map[string]*clientStr),
}
}

23 changes: 0 additions & 23 deletions server/server.go
Original file line number Diff line number Diff line change
@@ -1,26 +1,3 @@
/*
MIT License
# Copyright (c) 2021 Mohammad Issawi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
package server

import (
Expand Down

0 comments on commit c4140e0

Please sign in to comment.