Skip to content

Commit 187e8f7

Browse files
author
Jerjou Cheng
committed
Add GAE standard + firebase tictactoe sample
1 parent 012874e commit 187e8f7

File tree

16 files changed

+1125
-0
lines changed

16 files changed

+1125
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Tic Tac Toe on Google App Engine Standard using Firebase
2+
3+
This directory contains a project that implements a realtime two-player game of
4+
Tic Tac Toe on [Google App Engine] Standard, using the [Firebase] database
5+
for realtime notifications when the board changes.
6+
7+
[Firebase]: https://firebase.google.com
8+
[Google App Engine]: https://cloud.google.com/appengine
9+
10+
## Prerequisites
11+
12+
* Install [Apache Maven][maven]
13+
* Create a project in the [Firebase Console][fb-console]
14+
* Install the [Google Cloud SDK][sdk]
15+
* Download [service account credentials][creds] and move it to
16+
`src/main/webapp/resources/credentials.json`.
17+
* In the [Overview section][fb-overview] of the Firebase console, click 'Add
18+
Firebase to your web app' and replace the contents of the file
19+
`src/main/webapp/resources/firebase_config.html` with that code snippet.
20+
21+
[fb-console]: https://console.firebase.google.com
22+
[sdk]: https://cloud.google.com/sdk
23+
[creds]: https://console.firebase.google.com/iam-admin/serviceaccounts/project?project=_&consoleReturnUrl=https:%2F%2Fconsole.firebase.google.com%2Fproject%2F_%2Fsettings%2Fgeneral%2F
24+
[fb-overview]: https://console.firebase.google.com/project/_/overview
25+
26+
27+
## Run the sample
28+
29+
* To run the app locally:
30+
31+
```sh
32+
$ mvn appengine:run
33+
```
34+
35+
## Troubleshooting
36+
37+
* If you see the error `Google Cloud SDK path was not provided ...`:
38+
* Make sure you've installed the [Google cloud SDK][sdk]
39+
* You may have installed it in a non-standard path. In that case, set the
40+
environment variable `GOOGLE_CLOUD_SDK_HOME` to point to where you
41+
installed the SDK:
42+
43+
```sh
44+
export GOOGLE_CLOUD_SDK_HOME=/path/to/google-cloud-sdk
45+
```
46+
47+
## Contributing changes
48+
49+
See [CONTRIBUTING.md](../../CONTRIBUTING.md).
50+
51+
## Licensing
52+
53+
See [LICENSE](../../LICENSE).
54+
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
<!--
2+
Copyright 2015 Google Inc. All Rights Reserved.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
<project>
17+
<modelVersion>4.0.0</modelVersion>
18+
<packaging>war</packaging>
19+
<version>1.0-SNAPSHOT</version>
20+
<groupId>com.example.appengine</groupId>
21+
<artifactId>appengine-firebase</artifactId>
22+
<parent>
23+
<groupId>com.google.cloud</groupId>
24+
<artifactId>doc-samples</artifactId>
25+
<version>1.0.0</version>
26+
<relativePath>../..</relativePath>
27+
</parent>
28+
<properties>
29+
<objectify.version>5.1.13</objectify.version>
30+
</properties>
31+
<!-- [START set_versions] -->
32+
<prerequisites>
33+
<maven>3.3.9</maven>
34+
</prerequisites>
35+
<!-- [END set_versions] -->
36+
<dependencies>
37+
<dependency>
38+
<groupId>com.google.appengine</groupId>
39+
<artifactId>appengine-api-1.0-sdk</artifactId>
40+
<version>${appengine.sdk.version}</version>
41+
</dependency>
42+
<dependency>
43+
<groupId>javax.servlet</groupId>
44+
<artifactId>servlet-api</artifactId>
45+
<version>2.5</version>
46+
<type>jar</type>
47+
<scope>provided</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.json</groupId>
51+
<artifactId>json</artifactId>
52+
<version>20160810</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>com.googlecode.objectify</groupId>
56+
<artifactId>objectify</artifactId>
57+
<version>${objectify.version}</version>
58+
</dependency>
59+
60+
<!-- Test Dependencies -->
61+
<dependency>
62+
<groupId>junit</groupId>
63+
<artifactId>junit</artifactId>
64+
<version>4.12</version>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.mockito</groupId>
69+
<artifactId>mockito-all</artifactId>
70+
<version>1.10.19</version>
71+
<scope>test</scope>
72+
</dependency>
73+
<dependency>
74+
<groupId>com.google.appengine</groupId>
75+
<artifactId>appengine-testing</artifactId>
76+
<version>${appengine.sdk.version}</version>
77+
<scope>test</scope>
78+
</dependency>
79+
<dependency>
80+
<groupId>com.google.appengine</groupId>
81+
<artifactId>appengine-api-stubs</artifactId>
82+
<version>${appengine.sdk.version}</version>
83+
<scope>test</scope>
84+
</dependency>
85+
<dependency>
86+
<groupId>com.google.appengine</groupId>
87+
<artifactId>appengine-tools-sdk</artifactId>
88+
<version>${appengine.sdk.version}</version>
89+
<scope>test</scope>
90+
</dependency>
91+
<dependency>
92+
<groupId>com.google.truth</groupId>
93+
<artifactId>truth</artifactId>
94+
<version>0.30</version>
95+
<scope>test</scope>
96+
</dependency>
97+
<dependency>
98+
<groupId>com.google.firebase</groupId>
99+
<artifactId>firebase-server-sdk</artifactId>
100+
<version>3.0.1</version>
101+
</dependency>
102+
<dependency>
103+
<groupId>com.google.api-client</groupId>
104+
<artifactId>google-api-client-appengine</artifactId>
105+
<version>1.22.0</version>
106+
</dependency>
107+
</dependencies>
108+
<build>
109+
<!-- for hot reload of the web application -->
110+
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes
111+
</outputDirectory>
112+
<plugins>
113+
<plugin>
114+
<groupId>com.google.cloud.tools</groupId>
115+
<artifactId>appengine-maven-plugin</artifactId>
116+
<version>1.0.0</version>
117+
</plugin>
118+
</plugins>
119+
</build>
120+
</project>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.appengine.firetactoe;
18+
19+
import com.google.appengine.api.users.UserService;
20+
import com.google.appengine.api.users.UserServiceFactory;
21+
import com.googlecode.objectify.Objectify;
22+
import com.googlecode.objectify.ObjectifyService;
23+
24+
import java.io.IOException;
25+
import javax.servlet.http.HttpServlet;
26+
import javax.servlet.http.HttpServletRequest;
27+
import javax.servlet.http.HttpServletResponse;
28+
29+
public class DeleteServlet extends HttpServlet {
30+
@Override
31+
public void doPost(HttpServletRequest req, HttpServletResponse resp)
32+
throws IOException {
33+
String gameId = req.getParameter("gameKey");
34+
Objectify ofy = ObjectifyService.ofy();
35+
Game game = ofy.load().type(Game.class).id(gameId).safe();
36+
37+
UserService userService = UserServiceFactory.getUserService();
38+
String currentUserId = userService.getCurrentUser().getUserId();
39+
40+
game.deleteChannel(currentUserId);
41+
}
42+
}

0 commit comments

Comments
 (0)